zoukankan      html  css  js  c++  java
  • ajax防止重复提交

     //防止重复提交
        var pendingRequests = {};
        jQuery.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
            var key = options.url;
            i=0;
            i++;
            console.log(key+"aaaaaaaaaaa"+i);
            if (!pendingRequests[key]) {
                pendingRequests[key] = jqXHR;
            }else{
    //jqXHR.abort(); //放弃后触发的提交
                setTimeout(function(){console.log("放弃先触发的提交");},1);
                pendingRequests[key].abort(); // 放弃先触发的提交
            }
            var success = options.success;
            options.success = function(jqXHR, textStatus) {
                pendingRequests[key] = null;
                if (jQuery.isFunction(success)) {
                    success.apply(this, arguments);
                }
            };
            var error = options.error;
            options.error = function(jqXHR, textStatus) {
                pendingRequests[key] = null;
                if (jQuery.isFunction(error)) {
                    error.apply(this, arguments);
                }
            };
        });
     
    注意:ajax必须是异步时,这段代码才有效果
    学而不思则罔,思而不结则殆,结而不看,一事无成
  • 相关阅读:
    python 运行CMD和shell命令
    python 装饰器2 常用装饰器【@property,@x.setter,@x.deleter】
    正则表达式 python re正则模块
    Interesting Finds: 2008.01.06
    Interesting Finds: 2008.01.11
    Interesting Finds: 2007.12.25
    Interesting Finds: 2007.12.26
    Interesting Finds: 2008.01.04
    Interesting Finds: 2008.01.03
    Interesting Finds: 2008.01.09
  • 原文地址:https://www.cnblogs.com/windseek/p/6408410.html
Copyright © 2011-2022 走看看