jQuery AJAX没有进入“成功”

时间:2015-04-14 17:40:51

标签: javascript jquery ajax json

$(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);
            }
        });
    });
});

所以这是我的应用程序的jQuery部分,它成功执行第一个ajax调用,并从" window.alert(5)显示5;"第二次调用已经完成但由于某种原因未触发成功。以下是" lessons.php"的输出方式。看起来像

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

1 个答案:

答案 0 :(得分:3)

这是无效的json:

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

也许将其格式化为:

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