如何使jquery.ajax触发成功或错误?

时间:2013-12-17 23:45:22

标签: javascript jquery ajax json

我正在尝试从PHP脚本中获取JSON,使用以下代码:

var myUrl = "http://....er.com";

function getJson() {
    jQuery.ajax({

        url: myUrl,
        dataType: "json",
        contentType: "application/json",
        timeout: 3000,
        async: false,
        cache: false,
        success: function (respJSON) {
        console.log("OK");

        },
        error: function () {
            console.log("NOTOK");
        }

    });
}

当我查看浏览器时,URL成功返回有效的JSON:

{"RESPONSE_CODE" : "OK","RESPONSE_MESSAGE" : [{"id" : "9","denominazione" : "ADV0001","lat" : "0","lng" : "0","idTerritorio" : "1","idCRM" : "MOVENTU"}]}

但我不明白为什么我的控制台中的日志不是“OK”日志既不是“NOTOK”日志,而是我得到Uncaught TypeError: Cannot read property 'loader' of undefined

我做错了什么?

0 个答案:

没有答案