0
我有以下代碼檢測有關ajax的任何錯誤,我需要專門爲ajax獲取「abort」錯誤。如何在AJAX中捕獲AJAX中止?
怎麼辦?
$(document).bind("ajaxError", function (e, jqXHR, ajaxSettings, thrownError) {
});
我不確定if (thrownError == "abort")
是否是正確的方法。
我有以下代碼檢測有關ajax的任何錯誤,我需要專門爲ajax獲取「abort」錯誤。如何在AJAX中捕獲AJAX中止?
怎麼辦?
$(document).bind("ajaxError", function (e, jqXHR, ajaxSettings, thrownError) {
});
我不確定if (thrownError == "abort")
是否是正確的方法。
是的,你是atmost沒有看到這一個
$(function() {
$.ajaxSetup({
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.n' + jqXHR.responseText);
}
}
});
});
,供您參考http://www.sitepoint.com/jquery-ajax-error-handling-function/
希望這有助於:)