可以使用,这个
$.ajax({
statusCode: {
404: function() {
alert( "page not found" );
}
}
});
如果请求成功,状态代码对应的函数作为回调的成功相同的参数;如果在一个错误的结果,他们采取了相同的参数error
回调。
或者
$.ajaxSetup({
type: "GET",
dataType: "jsonp",
error: function(xhr, exception){
if( xhr.status === 0)
alert('Error : ' + xhr.status + 'You are not connected.');
else if( xhr.status == "201")
alert('Error : ' + xhr.status + '\nServer error.');
else if( xhr.status == "404")
alert('Error : ' + xhr.status + '\nPage note found');
else if( xhr.status == "500")
alert('Internal Server Error [500].');
else if (exception === 'parsererror')
alert('Error : ' + xhr.status + '\nImpossible to parse result.');
else if (exception === 'timeout')
alert('Error : ' + xhr.status + '\nRequest timeout.');
else
alert('Error .\n' + xhr.responseText);
}
});