连续点赞异步触发计数

阅读更多
    防止连续触发异步请求,2秒发送一次计数

  
 
    var view_count_num=0;
    var view_count_status=true;
    $('.journal-reward').on('click',  function(event) {
       view_count_num++;
       if(view_count_status){
           view_count_status = false;
           setTimeout(function(){
              $.ajax({
                url: '/articles/add_view_count',
                data: {id:<%= @article.id%>,view_count:view_count_num},
                type: "get",
                success: function(data){
                  view_count_status = true;
                  $("#view_count").html(data["view_count"]);
                }
              });
              view_count_num = 0;
           },2000);
        }
    });

你可能感兴趣的:(连续点赞异步触发计数)