开发者

Ajax calls prevent massive requests calls

Which is the best way/plugin/method to prevent users launching t开发者_StackOverflowoo many xhr request by clicking many times/sequentially ( :|) on a xhr button?

i'm using jQuery.


This is what I usually do:

$("button").click(function(e){
    var $this = $(this);
    if(!$this.data("ajaxCall")){
        var xhr = $.ajax({
            options here,
            complete: function(){
                $this.removeData("ajaxCall");
            }
        });
        $this.data("ajaxCall", xhr)
    }
});


you could remove the click event at the start of your function, and then add the click event back.


You can disable your button.

$('.someElement').attr('disabled', 'disabled');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜