【问题标题】:Simple form for remote true responding with html使用 html 进行远程真实响应的简单表单
【发布时间】:2015-09-24 22:57:32
【问题描述】:

我有一个带有远程 true 的表单。当我点击提交时,我只用 js 响应。问题是服务器没有用 javasctipt 响应,而是用 html 响应。

我的表格。

= simple_form_for @company, :remote => true,  :url => {:controller => 'companies', :action => 'update_company'}, :html => { :multipart => true, :class => 'company_name' }  do |f|
  = f.input :name
  = f.input :submit

在我的控制器中

def update_company
  if @company.update(company_attributes)
    respond_to do |format|
      format.js
    end
  end
end

我需要所有 jquery 文件。 这在任何地方都有效,但在此操作中。

我来自服务器的响应标头:

Connection:keep-alive
Content-Length:0
Content-Type:text/html; charset=utf-8
Date:Thu, 24 Sep 2015 22:02:17 GMT
Server:nginx/1.8.0 + Phusion Passenger 5.0.13
Status:406 Not Acceptable
Strict-Transport-Security:max-age=31536000
X-Powered-By:Phusion Passenger 5.0.13

我的请求头:

Accept:text/javascript
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:1048
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie: _LongFreakingHash

如果您需要更多信息,请告诉我。我在这里不知所措。 如果您以前遇到过这种情况,您的意见将对我有很大帮助。

【问题讨论】:

    标签: javascript jquery html ruby-on-rails


    【解决方案1】:

    尝试更改此设置

    = simple_form_for @company, :remote => true,  :url => {:controller => 'companies', :action => 'update_company'}, :html => { :multipart => true, :class => 'company_name' }  do |f|
    

    = simple_form_for @company, :url => {:controller => 'companies', :action => 'update_company', :remote => true }, :html => { :multipart => true, :class => 'company_name' }  do |f|
    

    【讨论】:

      猜你喜欢
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      相关资源
      最近更新 更多