gpt4 book ai didi

javascript - 全局和特定错误处理AJAX jQuery

转载 作者:行者123 更新时间:2023-12-03 09:07:04 25 4
gpt4 key购买 nike

我有如下全局处理。

$.ajaxSetup({
statusCode: {

200: function(res, status, xhr) {
},
500: function() {
},

400: function(jqXHR, textStatus, errorThrown) {
},
});

我在 Backbone 模型获取中进行以下特定处理。
var xhr = byBackbone.fetch({//or save
success: function(){},
error: function(){
if(xhr.statusCode == 400 && xhr.data == "some specific response"){
//specefic handling
} else {
//how to call statusCode.400() here or how to leave it for getting handled globally?
}
}
});

因此,就像在评论中一样,问题是,如何在捕获特定错误后如何使其在全局范围内得到处理?

最佳答案

大概-

var cb = $.ajaxSetup({
statusCode: {

200: function(res, status, xhr) {
},
500: function() {
},

400: function() {
}
}});

cb.statusCode[400](); // put this in your backbone ajax response handler

http://jsfiddle.net/hellomaya/rFhRW/1/

关于javascript - 全局和特定错误处理AJAX jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18823087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com