【发布时间】:2012-02-29 21:24:05
【问题描述】:
我在 ajax 成功时遇到 jquery 实时触发的问题。这是我的 link_to 函数。
<%= link_to image_tag("cross.png"), patient_recurrence_detail_path(params[:id],f.object.id), :remote => true, :class => 'delete_recurrence_detail', :method => :delete, :confirm=>'Are you sure you?' %>
它调用的方法是this
def destroy
@recurrence_detail = RecurrenceDetail.find(params[:id])
@recurrence_detail.destroy
respond_to do |format|
format.html { redirect_to patient_path(params[:patient_id]) }
format.js { render :nothing => true }
end
end
最后,我在创建的链接上附加了一个 jquery live 函数。 (我在这里使用 .bind() 无济于事)
$('a[data-method="delete"]').live("ajax:success", function(data, textStatus, jqXHR){
$(this).parents('div.fields').remove();
});
我注意到在我的网络流量中,我之前收到了删除的 OK 状态,所以我对为什么没有调用 live 函数有点困惑。注意:我也尝试过使用 .bind() 。我确实有 jquery-rails gem。
更新:我尝试使用 .ajaxSuccess() 并更新了我的 gem,但仍然没有成功。我是否需要在我的 respond_to 中添加一些内容以用于 ajax?
【问题讨论】:
-
可能是在事件名称中使用冒号的语法问题,如果 ajax:before 不是自定义事件,那肯定是个问题
-
抱歉,已编辑帖子。我的意思是在那里有 ajax:success。
-
ajasSuccess 是一个方法api.jquery.com/ajaxSuccess 没见过绑定的,使用方法语法更安全
-
真的看不出你在做什么来提供帮助,可能会启动一个更关注 ajax 客户端 js 代码的线程
-
你的
jquery-rails是什么版本的?
标签: jquery ajax ruby-on-rails-3