.done没有在ajax调用上触发

时间:2016-04-11 16:32:45

标签: javascript ajax

我有一个进行ajax调用的函数。 .done似乎没有被解雇。我检查了控制台上的错误。它说

enter image description here

function getIncidentInfo() {
    $.ajax({
        type: "GET",
        url: "../../page_components/statsboard/stats.php",
        data: $(this).serialize(),
        dataType: "json",
    }).done(function(response) {
        incidentAr = response;
        for (var i in incidentAr) {
            var zaNorth = parseInt(incidentAr[i].zaNorth);
            ......
        }
    }).fail(function(xhr, status, error) {
        console.log("Status: " + status + " Error: " + error);
        console.log(xhr);
    });
}

我让我的朋友尝试使用相同的代码并且它有效。

2 个答案:

答案 0 :(得分:0)

stats.php中的脚本抛出了一个XDebug错误,并返回描述错误的HTML而不是您期望的JSON。在浏览器中加载stats.php页面,或检查PHP日志以找出错误。

答案 1 :(得分:0)

  1. 检查.always(response)而不是.done(response)。某些服务返回非200代码,并带有响应正文来描述错误。
  2. 检查response.responseJSONresponse.responseTextresponse.responseXML。您可能必须说明response.responseJSON = eval(respaonse.responseText)
  3. 但是,我发现responseText属于HTML类型,所以我的猜测(我说这是因为你获得200状态,而不是404或500)是你得到的更通用的服务器错误,它会从您不打算查询的路由中呈现响应。

相关问题