$. ajax -> I’m lost with this error "Uncaught Referenceerror: $ is not defined"

Asked

Viewed 1,628 times

-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 inserir a descrição da imagem aqui

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>.

2 answers

1

Change the line below, change rsc to src:

<script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript" ></script>

And below a functional model of the script:

function carregarCEP(){
            var url = 'https://cep.awesomeapi.com.br/json/54230120';
            $.ajax({
                    url: url,
                    dataType: 'json',
                    crossDomain: true,
                    success : function(json){
                        if(json.cep){

                                $("#tabela tbody").html(json.cep);
                        }
                    }
            });
        }   
  • My God <o>, has greatly improved my code. Now just pack a few things inside and ready, finished project. Thank you very much <3

0


You put <script rsc="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript" ></script> the correct is <script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript" ></script>

The Script call parameter is src from "Source". It is normal to err on these things at the beginning man. Good studies.

  • That was right, after that fix, the business went better, then Clenir Santos gave a strength in the bass comment and now things already so far running, kkkkkk thank you very much guy, from heart , thanks very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.