这是我用来从其他服务获得响应的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);
是:当前响应是错误状态是内部服务器错误响应是[对象对象]
如何阅读响应对象?正如你所看到的,Json.parse无法正常工作,还有其他的东西吗?
&安培;这是一种正确的方法还是有更好的方法?
答案 0 :(得分:1)
console.dir( <object> );
会将对象的内容打印到控制台。
这样:
console.log("Response is: ");
console.dir(response);
应该做的伎俩