ajax - 轨道 3 :remote => true does not trigger AJAX requests

标签 ajax ruby-on-rails-3

我有以下内容:

<%= link_to "Exhibitions", :action => 'tabExhibitions', :id => @app.id, :remote => true %>

它生成:

<div class="tabbarButton" id="tabbarExhibitions">
    <a href="/apps/3/tabExhibitions?remote=true">Exhibitions</a>
</div>

单击时会产生常见的 GET 请求。

我是 Rails 新手,但我的理解是设置 :remote => true应该创建一个 <a href="..." data-remote=true>而不是简单的链接。

我正在使用 jQuery,必要的 header 和元标记已就位。我应该提到这个项目是从 Rails 2.3.8 升级的

感谢您的帮助。

最佳答案

link_to:remote => true 放入参数列表的 url 部分,并为其创建一个查询字符串参数(参见参数 in the documentation )。本质上,您所写的是:

<%= link_to "Exhibitions", { :action => 'tabExhibitions', :id => @app.id, :remote => true } %>

您需要为 html_options 有一个单独的哈希:

<%= link_to "Exhibitions", { :action => 'tabExhibitions', :id => @app.id }, :remote => true %>

关于ajax - 轨道 3 :remote => true does not trigger AJAX requests,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5773544/

相关文章:

javascript - 如何构建 MustacheJS 模板以根据 JSON 文件中的值添加动态类?

ruby-on-rails - cancan - 处理巨大的ability.rb 文件

ruby-on-rails-3 - delayed_job :run_at is not working. 所有作业设置为在当前时间运行

ruby-on-rails - 神秘的 AbstractController::ActionNotFound (路由就在那里)

ruby-on-rails-3 - 如何从 mina 部署脚本运行自定义 rake 任务

javascript - 使用 jQuery,如何存储调用 $.ajax 函数的结果以供重复使用?

javascript - 如何通过prototype.js发送body和queryparam中的数据?

javascript - 如何使用 $.each 和 ajax 来获取 JSON?

php - Ajax 状态为 `success` 但回调无法正常工作

ruby - Ruby on Rails 中的实用程序类