나는 일반적인 아약스 오류 핸들러과 같이 썼다 : 오류가 403 아니다jQuery를 아약스 일반적인 오류 처리 및 경우에 따라
$('html').ajaxError(function(e, xhr, settings, exception) {
var message = '';
if (xhr.status == 0) {
message = 'You are offline!\n Please check your network.';
}
else if (xhr.status == 403) {
window.location.href = $('#logon').attr('href');
}
else if (xhr.status == 404) {
message = 'Requested URL not found.';
}
else if (xhr.status == 500) {
message = xhr.responseText;
$('#cboxLoadedContent div.news_article_content').append('<p>' + message + '</p>');
try {//Error handling for POST calls
message = JSON.parse(xhr.responseText);
}
catch (ex) {//Error handling for GET calls
message = xhr.responseText;
}
}
else if (errStatus == 'parsererror') {
message = 'Error.\nParsing JSON Request failed.';
}
else if (errStatus == 'timeout') {
message = 'Request timed out.\nPlease try later';
}
else {
message = ('Unknown Error.\n' + xhr.responseText);
}
if (message != '' && xhr.status != 500) {
message = message;
}
if (xhr.status != 403) {
$('#icis_dashboard').append('<p id="ajax_error_msg" class="offScreen">' + message + '</p>');
errorBox({
inline: true,
width: 0,
href: '#ajax_error_msg',
onLoadCall: function() { $('#cboxLoadedContent').jScrollPaneRemove(); },
onCleanupCall: function() { $('#ajax_error_msg').remove(); }
});
}
});
그래서 때 대화 상자가 텍스트에 관한 함께 표시됩니다 오류.
괜찮지 만 원래 처리기를 백업으로 사용하고 원래의 Ajax 호출에서 개별 오류를 처리해야합니다.
그래서 내가 대신 "foo는"경고하고 싶습니다 (404)의 백업 핸들러 경고 "바"로 :
error: function(xhr) {
if (xhr.status == 404) {
//window.location.href = $('#logon').attr('href');
alert("foo");
}
}
나는이 일을 어쨌든 sthere? 둘 다 순간에 방아쇠를 당기는 것처럼 백업이 실행되는 것을 방지하는 방법을 모르겠습니다.
당신이 바로이'(! handledLocally)의 경우'체크를 한 적이으로 false로'handledLocally' 변수를 재설정해야합니다 또한 멀티 스레딩 경쟁 조건의 위험에 처해 있습니다. – Basic
답변의 주석에 리셋을 포함 시켰습니다. jsfiddle을 보면 handlesLocally 변수가 재설정되었습니다. 예, 이것은 다중 스레드 조건의 위험을 감수하고 있지만 응용 프로그램이 무엇을하는지 모르는 상태에서 정상적으로 작동합니다. –