我有一个带有远程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
如果您需要更多信息,请与我们联系。我在这里不知所措。 如果您之前遇到过这种情况,那么您的输入将有助于我。
答案 0 :(得分: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|