Reg*_*dit 1 ajax error-handling jquery
在下面的存根代码中,当调用error:方法时,"errorThrown"变量只返回"object Object".
如何打印出实际文本呢?
jQuery.ajax
({
contentType: "application/json; charset=utf-8",
dataType: "json",
url: myURL,
success: function(data)
{
if(data['response'] === undefined){
this.error('No data returned');
}
//success code goes here
},
error: function(errorThrown)
{
result += errorThrown;
alert('The error was: '+errorThrown);
return;
}
});
Run Code Online (Sandbox Code Playgroud)
错误函数接收三个参数.第一个是jQueryXmlHttpRequest对象,第二个和第三个对你可能有用:
error: function(jqXHR, textStatus, errorThrown){
alert('Error Message: '+textStatus);
alert('HTTP Error: '+errorThrown);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7584 次 |
| 最近记录: |