$.ajax ex.message,jQuery ajax泛型错误处理,并根据具体情况而定

我有一个通用的ajax错误处理程序,如下所示:

$('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('

' + message + '

');

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('

' + message + '

');

errorBox({

inline: true,

width: 0,

href: '#ajax_error_msg',

onLoadCall: function() { $('#cboxLoadedContent').jScrollPaneRemove(); },

onCleanupCall: function() { $('#ajax_error_msg').remove(); }

});

}

});

因此,当错误不是403时,会显示一个对话框,其中包含与错误相关的文本.

这很好,但我想做的是将通用处理程序作为备份,然后在原始ajax调用中单独处理每个错误.

因此备份处理程序警告404上的"bar"我想提醒"foo":

error: function(xhr) {

if (xhr.status == 404) {

//window.location.href = $('#logon').attr('href');

alert("foo");

}

}

无论如何我都坚持这样做?我不知道如何阻止备份触发,因为它们似乎都在此刻触发.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值