1

I just upgraded an application from Rails 2.3 to Rails 3.0. This application make extensive use of Ajax.

Since the upgrade, each

respond_to do |format|
  format.js
end

Responds with a content type of text/html instead of text/javascript (as viewed in Firebug). The XHR request specifies Accept="text/javascript". The result is that Prototype refuse to eval the response, so no more magic on my pages…

For precision, I decided to include the legacy RailsPrototypeHelpers, the full UJS app will be the next application.

For information, I tried to put the js in js.rjs files: content-type is still 'text/html' I tried to inline js and force with render :update, :content_type => 'text/javascript': no luck, still answer with 'text/html' content_type.

Any suggestion is welcome.

Thank you.

2
  • Same happening here, but weirder. Chrome and Safari are ok. On Firefox, however, content type is set to text/javascript on first post request, but text/html on the second one, which gives me a 406. Using Rails 3.2.3 Commented Apr 17, 2012 at 5:15
  • This issue still exists although it doesn't seem to be affecting everyone: github.com/rails/rails/issues/14173. Commented May 27, 2015 at 4:34

1 Answer 1

2

I've been having a similar problem. I found that I could get it to return text/javascript if I added this:

headers["Content-Type"] = "text/javascript; charset=utf-8"
render :update do |page|
    ...
end

or

respond_to do |format|
    format.js {headers["Content-Type"] = "text/javascript; charset=utf-8"}
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.