【发布时间】:2012-12-24 10:33:53
【问题描述】:
我正在使用以下代码发送一个可以正常工作的 ajax 请求,但是当用户多次单击链接时会产生问题,所以我想禁用我的链接,以便在用户第二次单击时不会调用 ajax .
.html.erb
<%= link_to("Sports", "#", :class => "school_activity", :p_type => "Sport", :o_type => "")%>
javascript
jQuery(function () {
jQuery('.school_activity').click(function () {
link = jQuery(this);
p_type = link.attr('p_type');
o_type = link.attr('o_type');
jQuery('.i-link a').removeClass('stream_wall_select');
jQuery.ajax({
type:"GET",
url:'<%= some_path(@school) %>',
data:'format=js&p_type=' + p_type + '&tagged_type=' + o_type,
success:function (response) {
jQuery('#s_activity_div').html(response);
}
});
})
})
我不想设置参数 true/false 并依赖它发送 ajax 请求。
我想要一些非常通用的东西,可能适用于我网站上的所有 ajax 链接。
【问题讨论】:
-
@salil 只需放置 $('.my-link').click(function () {return false;});在 ajax 调用中的成功回调中
标签: jquery ajax ruby-on-rails-3.1 disable-link