rails sending the wrong content-type in ajax response

我们两清 提交于 2019-12-11 00:59:51

问题


I have been struggling terribly for the better part of the day with the following problem:

  • I have a rails 3.1 app - running fine
  • I am trying to add some ajax to it

However, no matter what I try, Rails insists on sending the wrong content-type in the response header.

#the form    
= form_for @signup, :url => '/signup', :remote => true do |f|
    = f.text_field :email, :class => 'email', :size => 26
    = f.submit 'Notify me'

#In the controller
def create
  respond_to do |format|
    format.js { render :content_type => 'text/javascript', :layout => false}
  end
end

#the JS file: create.js.erb
alert('HI!');

This is not working, while I think it should. Inspecting the server response with Firebug it tells me the response header has a content-type of text/html. I figure this is why it isn't working (as on a newly generated app, using the same jquery-rails gem it responds with a text/javascript header.

The server says it's responding with JS:

Processing by SignupsController#create as JS

But is somehow refusing to send the correct header. I am lost on where to look next.

Any help or direction as to where to look next would be greatly appreciated! Erwin


回答1:


Ok found the solution,

So an after_filter in application controller was overriding the content-type. And they are processed inside out. So it was overwriting my declarations.



来源:https://stackoverflow.com/questions/7482742/rails-sending-the-wrong-content-type-in-ajax-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!