小编典典

rails 3.1提交一个带有链接的ajax(远程:true)表单

ajax

在Rails 3.1应用程序上使用Ajax,我需要能够使用链接而不是提交按钮来提交ajax表单(带有remote:true)。

我需要对链接(或表单)进行什么操作以使其以Ajax形式而不是普通形式提交?我尝试将onclick
java添加到链接中,但是在每种情况下,它只是以非ajax方式(页面刷新)提交表单。

目前,使用提交按钮可以使ajax窗体正常工作,因此它必须很小。

谢谢!


阅读 268

收藏
2020-07-26

共1个答案

小编典典

使用:remote => trueAjax事件创建表单时,该事件绑定到表单的“提交”按钮。您必须使用javascript触发该事件。这是我用来完成类似操作的一些代码:

<%= form_for [item.list, item], :remote => true, :html => { :'data-type' => 'json', :id => 'change-completed-form' } do |f| %>
    <td><%= f.label :name, item.name %></td>
    <td><%= f.check_box :completed, :onClick => "this.form.submit_button.click();" %></td>
    <%= f.submit :id => 'submit_button', :style => 'display: none;' %>
<% end %>
2020-07-26