【问题标题】:ajax rendered form will not submitajax 呈现的表单将不会提交
【发布时间】:2014-02-10 04:50:54
【问题描述】:

当有人单击显示表单按钮时,我有一个通过 ajax 呈现的表单。表单正确呈现,但未提交。当我按下提交时,什么也没有发生,服务器也没有收到任何东西。这是表格:

<%= form_for @employer_profile, :html => { :class => "clearfix", :id => "the_form"}, 
    remote: true do |f| %> 
    <%= f.text_field :position, class: "field" %>
<%= f.submit "SAVE", class: "button button-save button-submit" %>

这是生成的html:

<form id="the_form" class="clearfix" method="post" data-remote="true" 
 action="/employer_profiles/13" accept-charset="UTF-8"
    <input id="employer_profile_position" class="field" type="text"
     name="employer_profile[position]"></input>
<input class="button button-save button-submit" type="submit" value="SAVE" 
 name="commit"></input>

为什么表单没有提交?

【问题讨论】:

  • 你可以显示生成的动作。
  • 没有生成任何东西。我只是点击提交,没有任何反应。
  • 显示html代码并寻找form action="..."
  • jquery_ujs.js 是否包含在您的 html 代码中?否则remote 不起作用。
  • 它包含在具有加载ajax表单的按钮的原始页面上。我尝试将它包含在表单页面上,但这并没有使表单工作。

标签: ruby-on-rails ajax jquery ruby-on-rails-4 ajaxform


【解决方案1】:

您是否尝试通过在调用中添加remote: true 参数来更改提交按钮以发送AJAX 请求?

&lt;%= f.submit "SAVE", class: "button button-save button-submit", remote: true %&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-06
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 2022-10-13
    相关资源
    最近更新 更多