-1

我有如下全局处理。

$.ajaxSetup({
    statusCode: {

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

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

我在骨干模型提取中进行如下特定处理。

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?
    }
    }
});

因此,在评论中,问题是,在捕获特定错误后如何让它在全球范围内得到处理?

4

1 回答 1

1

大概 -

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/

于 2013-09-16T08:45:17.143 回答