开发者

Ajax calls prevent massive requests calls

开发者 https://www.devze.com 2023-03-30 22:42 出处:网络
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?

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

精彩评论

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

关注公众号