1

这是我用来从其他服务获取响应的 ajax 调用:

$.ajax({
    url: xxxxx,
    cache: false,
    dataType: 'json',
    data: JSON.stringify(xxxx),
    type: "POST",
    contentType: 'application/json; charset=utf-8',
    async: asyncType,
    headers: { "ASP.NET_SessionId": apiReadCookie() },
    success: function (data, textStatus, jqXHR) {
        callback(data, paramters);
    },
    error: function (xhr, jqXHR, status, text) {
        var response = JSON.parse(xhr.responseText);
        console.log("The Current Response is " + jqXHR + " The Status is " + status + " The response is " + response);
        if (response) {
            console.log(response.error);
        } else {
        }
    }
});

我从这一行得到的输出:

            console.log("The Current Response is " + jqXHR + " The Status is " + status + " The response is " + response);

是:当前响应是错误状态是内部服务器错误响应是[object Object]

如何读取响应对象?如您所见,Json.parse 不起作用,还有其他问题吗?

&这是一个正确的方法还是有更好的方法?

4

1 回答 1

1
console.dir( <object> );

将对象的内容打印到控制台。

所以:

console.log("Response is: ");
console.dir(response);

应该做的伎俩

于 2013-05-09T09:51:37.707 回答