开发者

Extending jQuery for recursive ajax method

i would like to know if is possible to generate a method/extension/change for the jQuery lib to specify for all $.ajax() calls a method to be executed for example in timeo开发者_运维问答ut:, or in beforeSend:, statments


Of course. There are many ways, but one of the simple methods for having a centralized method to be run on every ajax call, is to wrap jQuery ajax in your custom ajax wrapper.

(function ($){
    $.customAjax = function(path, data, successCallback, errorCallback){
        function errorFallback(){
             // Here, do what you want to do on any ajax call, which doesn't have error     callback
        };
        errorCallback= errorCallback|| errorFallback;
        $.ajax({
              // Calling the jQuery ajax, passing either specified error callback or a   default callback.
        });
    };
})(jQuery);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜