JQuery重写ajax

来源:互联网 发布:2017淘宝考试答案50题 编辑:程序博客网 时间:2024/05/21 10:30
        (function ($) {            //备份jquery的ajax方法              var _ajax = $.ajax;            //重写jquery的ajax方法              $.ajax = function (opt) {                //备份opt中error和success方法                  var fn = {                    error: function (XMLHttpRequest, textStatus, errorThrown) { },                    success: function (data, textStatus) { }                }                if (opt.error) {                    fn.error = opt.error;                }                if (opt.success) {                    fn.success = opt.success;                }                //扩展增强处理                  var _opt = $.extend(opt, {                    error: function (XMLHttpRequest, textStatus, errorThrown) {                        $.loadCookiesForAjax(opt, errorThrown, function () {                            fn.error(XMLHttpRequest, textStatus, errorThrown);                        });                    },                    success: function (data, textStatus) {                        if (typeof (loadnumberForAjax) != "undefined" ) {                            loadnumberForAjax = 0;                        }                        if (typeof (loadnumber) != "undefined" ) {                            loadnumber = 0;                        }                        //成功回调方法增强处理                          fn.success(data, textStatus);                    }                });                _ajax(_opt);            };        })(jQuery);

0 0
原创粉丝点击