Actaeonis
Actaeonis

Reputation: 159

AJAX succes not firing

I'm trying to get a JSON string through an ajax call with JQuery, however the succes method is not firing. When I check the status through the complete method it does show code 200 and succes.

    function init() {
    $.ajax( {
       type: "GET",
       dataType: "json",
       url:"posts.json",
       succes: loadedSucces,
       error: loadedError,
       complete: loadedComplete
    });
}

function loadedSucces(data,textStatus,jqXHR) {
    var jsonObject = data;
    $.each(jsonObject, function(key, val) {
       console.log("\n" + key + "  ====> " +val  + "\n");

    }); 
}

    function loadedComplete(data, textStatus, jqXHR) {
        console.log(textStatus);
        console.log(data);
    }

function loadedError(jqXHR,textStatus,errorThrown) {
 console.log(jsonStatus+": "+errorThrown);   
}

Complete console output:

success
postHandler.js:29 Object {readyState: 4, responseText: "[{"id":0,"title":" What is Lorem Ipsum ?","content… or non-characteristic words etc.\n","tags":[]}]↵", responseJSON: Array[4], status: 200, statusText: "OK"}

Upvotes: 1

Views: 48

Answers (1)

Vincent
Vincent

Reputation: 348

success is with 2 s's

function init() {
    $.ajax( {
       type: "GET",
       dataType: "json",
       url:"posts.json",
       success: loadedSucces,
       error: loadedError,
       complete: loadedComplete
    });
}

Upvotes: 2

Related Questions