在错误回调或$ .ajax中,您有三个输入参数:
function (XMLHttpRequest, textStatus, errorThrown) { this; // options for this ajax request}您可以直接检查
xhr.status以获得HTTP响应代码,例如:
$.ajax({ url: "test.html", cache: false, success: function(html){ $("#results").append(html); }, error: function (xhr, textStatus) { if (xhr.status == 500) { alert('Server error: '+ textStatus); } }});编辑: 告诉浏览器断开连接与服务器关闭的情况之间的区别(jasonmerino的评论):
卸载时,xhr.readyState应该为0,对于无响应服务器,xhr.readyState应该为4。



