防止jQuery中ajax重复提交

(function($){
    $.oneAjax = function(settings){
        if ($.oneAjax[settings.guid] === "isProcessing") {
            return false;
        }
        $.oneAjax[settings.guid] = "isProcessing";
        return $.ajax(settings).complete(function() {
          delete $.oneAjax[settings.guid];
      });
    };
})(jQuery);

 

调用方式和ajax一模一样只是加了一个guid参数而已

$.oneAjax({url:'http://jquery.com',success: function(){console.log("ok")}, guid:"key1"});

posted @ 2013-10-08 18:44  chenkychen  阅读(193)  评论(0)    收藏  举报