Hristo Temelski
Hristo Temelski

Reputation: 40

jQuery AJAX not entering "success"

$(function(){
    $(document).ready(function(){
        $.ajax({
            url: "src/cookiecheck.php",
            type: "POST",
            async: true,
            success: function(json){
                if(json.visitedBefore!="true"){
                    $("#cookiepolicy").fadeIn();
                }
            }
        });
        window.alert(5);
        $.ajax({
            url: "src/lessons.php",
            type: "POST",
            async: true,
            success: function(json){
                window.alert(1);
            }
        });
    });
});

So this is my jQuery part of the application it executes the first ajax call successfully and display 5 from the "window.alert(5);" The second call is made but for some reason success is not triggered. Here is how the output from "lessons.php" looks like

{"ID":"5"}
{"Name":["111","2","3","4","5","123123"]}
{"Location":["1112","2","3","4","5","3123123"]}

Upvotes: 0

Views: 476

Answers (1)

000
000

Reputation: 27247

This is not valid json:

{"ID":"5"}
{"Name":["111","2","3","4","5","123123"]}
{"Location":["1112","2","3","4","5","3123123"]}

Perhaps format it like this:

{
"things": {"ID":"5"},
"names": {"Name":["111","2","3","4","5","123123"]},
"locations": {"Location":["1112","2","3","4","5","3123123"]}
}

Upvotes: 3

Related Questions