我收到了来自AJAX请求的以下回复(根据Chrome控制台):
`XMLHttpRequest {
statusText: "Not Found",
status: 404,
responseURL: "XXX",
response: "{"apiVersion":"2.1","error":{"code":404,"message":…dException","internalReason":"User not found"}]}}", responseType: ""…`}
如何同时选择statusText
和internalReason
?
当我尝试设置var msg = response.data.statusText;
时,我得到Uncaught TypeError: Cannot read property 'statusText' of undefined
编辑:这里是上下文中的代码:
$.ajax({
type: "GET",
url: yt_url,
dataType:"json",
success: function(response)
{
// code
}
error: function(response)
{
handleError(response);
}
});
function handleError(response) {
var msg = response.data.statusText;
$('#status').html('An error occurred:' + msg);
}
答案 0 :(得分:2)
答案 1 :(得分:0)
如果您的json
是有效对象,那么您应该访问:
var msg = response.statusText // not response.data.statusText as there is not key as data