rails3 中的 Ajax 回调 [英] Ajax callbacks in rails3
本文介绍了rails3 中的 Ajax 回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 ajax 表单的 rails 2 中,我们可以有 ajax 回调,如 before、after 等.如何在 rails 3 中实现.
In rails 2 for a ajax form we can have ajax callbacks like before, after etc. How to do it in rails 3.
推荐答案
我遇到了同样的问题,这篇文章 帮我弄清楚了.基本上,您需要将一个侦听器附加到对 Rails 的回调事件做出反应的元素上.例如:
I'm having the same problem, and this post helped me figure it out. Basically you need to attach a listener to the element that reacts on rails' callback events. For example:
<%= link_to 'Delete', post,
:confirm => 'Are you sure?',
:method => :delete,
:remote=>true,
:id=>'delete' %>
在一个单独的 js 文件中(使其不引人注目),使用 jQuery:
In a separate js file (to make it unobtrusive), with jQuery:
$('#delete').bind('ajax:success', function() {
// do something
});
这篇关于rails3 中的 Ajax 回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文