轨道3.1提交一个Ajax(远程:真)的链接形式轨道、形式、链接、Ajax

2023-09-10 19:34:36 作者:穴而湿吸之

在轨3.1的应用程序,我需要能够提交一个Ajax的形式(带遥控:真)与Ajax的使用环节,而不是一个提交按钮。

Working with ajax on a rails 3.1 app, i need to be able to submit an ajax form (with remote: true) using a link rather than a submit button.

我需要什么做的链接(或表格),使其提交的阿贾克斯,而不是一个正常的表单提交?我曾尝试添加的onclick Java来的链接,但在每一种情况下,它只需提交表单在非Ajax的方式(页面刷新)。

what do i need to do to the link (or the form) to make it submit as ajax rather than a normal form submit? I have tried adding onclick java to the link, but in each case it simply submits the form in a non-ajax way (page refresh).

AJAX的形式目前工作正常使用一个提交按钮,因此它必须是一些小...

The ajax form currently works fine with using a submit button, so it's got to be something small...

谢谢!

推荐答案

在创建表格:远程=>真正的阿贾克斯事件被绑定到表单的提交按钮。您必须使用JavaScript来触发该事件。下面是一些code我用来完成类似的事情:

When you create a form with :remote => true the Ajax event is bound to the submit button of the form. You must use javascript to trigger that event. Here is some code I used to accomplish something similar:

<%= 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 %>