我确实有一个锚点,当按下该锚点时,它会发送ajax请求以交换元素,而在等待其执行时,我可以再次单击它并发送另一个请求。如何预防这种情况?
<% if current_or_guest_user.follow?(id_to_follow) %>
<%= link_to raw('<span class="glyphicon glyphicon-eye-close"></span> Unfollow'), unfollow_path(follow.id), method: "delete", remote: true,
class: 'btn btn-warning follow-link', id: 'unfollow'%>
<% else %>
<%= link_to raw('<span class="glyphicon glyphicon-eye-open"></span> Follow'), follow_path(following_id: id_to_follow), method: "post", remote: true,
class: 'btn btn-success follow-link', id: 'follow' %>
<% end %>
$(document).on('ajax:success',"#unfollow", function(xhr, data){
$(this).replaceWith(data['follow']);
});
$(document).on('ajax:success', "#follow", function(xhr, data){
$(this).replaceWith(data['follow']);
});