-4
Honestly, I started a little while ago in this area, and I’m lost, I can’t understand why this mistake continues.
This is my HTML
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<link rel="icon" type="favicon.png"/>
<script rsc="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript" ></script>
<script src="Script.js" type="text/javascript" ></script>
<title>Insert title here</title>
</head>
<body onload="carregarCEP()">
<section>
<h1>Endereço Por CEP</h1>
<h2></h2>
<table id = "tabela">
<caption>Agora Sim</caption>
<thead>
<th>cep</th>
<th>address_type</th>
<th>address_name</th>
<th>address</th>
<th>district</th>
<th>city</th>
<th>state</th>
<th>lat</th>
<th>lng</th>
<th>city_ibge</th>
<th>ddd</th>
</thead>
<tbody>
</tbody>
</table>
</section>
</body>
</html>
My ajax.php looks like this:
<?php
echo json_encode($_POST);
?>
Error ta appearing in Script.js , right in the first line, I think it should be something with my ajax.php, but I’m not able to evolve in this issue.
function carregarCEP (){ var iten="", url = "https://cep.awesomeapi.com.br/json/54230120"; $.ajax({ url: url, type: "GET", cache: false, dataType: 'json', beforeSend: function(){ $("h2").html("Corregando"); }, error:function(){ $("h2").html("fonte de dados com problemas"); }, sucess: function(retorno){ if (retorno[0].erro) {
$("h2").html(retorno.erro); } else{
for (var i = 0; i < retorno.length; i++) {
iten += "<tr>";
iten += "<td>" + retorno[i].cep +"</td>";
iten += "<td>" + retorno[i].address_type +"</td>";
iten += "<td>" + retorno[i].address_name +"</td>";
iten += "<td>" + retorno[i].address +"</td>";
iten += "<td>" + retorno[i].district +"</td>";
iten += "<td>" + retorno[i].city +"</td>";
iten += "<td>" + retorno[i].state +"</td>";
iten += "<td>" + retorno[i].lat +"</td>";
iten += "<td>" + retorno[i].lng +"</td>";
iten += "<td>" + retorno[i].city_ibge +"</td>";
iten += "<td>" + retorno[i].ddd +"</td>";
iten += "</tr>";
}
$("#tabela tbody").html(iten);
$("h2").html("Carregado"); } } }) }
if this is the case, you can copy the code and try to run it locally to better understand, but anyway, follow the print of the error that appears on my console
Maybe it’s a "beast" thing, but I’m lost.
The rsc attribute is wrong instead of
<script rsc="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript" ></script>
should be<script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript" ></script>
.– Guilherme Nascimento