Ricardo
Ricardo

Reputation: 25

ajax sucess function, dont appears items

Strange, I get 200 OK in firebug but return items are not displayed. Have tried using each and loop but without success. No error appears in the error function. Console.log messages and alerts are never displayed on the console.

$('#buscafrete').click(function(e) { 

    e.preventDefault();
    cep = $('#cep').val();
    $.ajax({
        type:'POST',
        url: "{% url 'get_frete' %}",
        dataType: "json",
        data: {
            data:cep,
            csrfmiddlewaretoken:'{{csrf_token}}',
        },        
        sucess: function(retorno){
            $.each(retorno, function(i, item) {
            console.log(i);
            console.log(item);
            console.log("TEST");
            alert("TEST");
            });                
        },
        error: function(jqXHR, textStatus, errorThrown){
            //alert("FALHOU");
            console.log('Error');
            console.log(jqXHR);
            console.log(textStatus);
            console.log(errorThrown);
        },
    });

});

Upvotes: 0

Views: 62

Answers (2)

Shiv Aggarwal
Shiv Aggarwal

Reputation: 499

there is an error in your success function there is spell mistake function should be success instead of sucess
it will not show any error but your code will not work.

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 599866

You have a typo: sucess should be success.

Upvotes: 1

Related Questions