gpt4 book ai didi

ruby-on-rails-3 - Rails 3 中使用 Prototype 而非 jQuery 的 Ajax 回调

转载 作者:行者123 更新时间:2023-12-01 11:57:40 24 4
gpt4 key购买 nike

我正在将应用程序从 Rails 2 升级到 Rails 3,并且正在重新设计所有远程功能以使用 Unobtrusive Javascript。我遇到困难的地方是在 UJS 中处理 ajax 回调。

我发现有很多资源展示了如何使用 jQuery 实现这些回调,但关于原型(prototype)的资源并不多。也许你可以帮我解决这个问题。

在 Rails 2 中,我有这个:

<% remote_form_for @foo, {:loading => "loading_function()", :complete => "complete_function()" } do |f| %>
...
<% end %>

在 Rails 3 中,我有这个:

<%= form_for @foo, :remote => true do |f| %>
....
<% end %>

根据我目前的了解(这可能是错误的),我需要将我的旧加载/完成函数附加到表单,以便它们将被 Rails.js 中的 handleRemote 函数触发。我只是不确定该怎么做。

同样,我在 Prototype 中执行此操作。因此,非常感谢针对该框架的特定答案。

最佳答案

答案如下:

<%= form_for @foo, :remote => true do |f| %>
...
<% end %>
...
<script type='text/javascript'>
$('edit_foo').observe('ajax:before', loading_function());
$('edit_foo').observe('ajax:complete complete_function());
</script>

关于ruby-on-rails-3 - Rails 3 中使用 Prototype 而非 jQuery 的 Ajax 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5397295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com