Miloslav21
Miloslav21

Reputation: 1

jQuery.ajax() don't fire handlers

I'm trying load json file (from localhost) named questions.json by function:

function loadJson() {
    $.ajax({
        dataType: "json",
        url: "questions.json",
        succes: function() {
            console.log("ajax succes");
        },
        error: function(object, error, errorThrow) {
            console.log("ajax fail");
            console.log(object);
            console.log(error);
            console.log(errorThrow);
        }

    });

}

and i run function in my script $(document).ready(loadJson());

In developer tools in Google Chrome looks everything OK (Status Code 200, preview shows valid json...), but console.log in both functions (succes and error) dont't write nothing. There aren't any other error messages.

If I change dataType to nonsense, function in error is fired.

What could be wrong?

Upvotes: 0

Views: 48

Answers (1)

Jai
Jai

Reputation: 74738

What could be wrong?

seems to be a typo with your success callback:

succes // <---missing a 's' in success

change to this:

success:function(){}

Upvotes: 1

Related Questions