406 Not Acceptable error when using Jquery $.post in Firefox but not in Safari or Chrome

Posted by jlfenaux on Stack Overflow See other posts from Stack Overflow or by jlfenaux
Published on 2010-02-11T09:12:20Z Indexed on 2010/04/11 10:33 UTC
Read the original article Hit count: 346

Filed under:
|
|

I'm using Jquery (1.3.2) $.post command to trigger an ajax call to a rails server.

The code works great on Safari and on Google Chrome (mac), but when I tried it on Firefox (3.5.7), I got a weird '406 Not Acceptable' error.

When I look at the headers, it Firefox indicated that it accepted only ' text/javascript' responses. And the response Content-Type was 'text/html; charset=utf-8'.

In Chrome the accepted types were 'application/json, text/javascript, /, text/javascript' and the response Content-Type was 'application/json; charset=utf-8'.

I tried to force the content type in rails to 'text/javascript'

format.json do
   render :json => @races.to_json, :content_type => 'text/javascript'
end

The content type is indeed changed in Chrome, but not in Firefox where it remains 'text/html'.

Here is the code I used to trigger the ajax call.

$.post(
    "/locator",
    params, 
    function(data){...},
    "json"
);

Is there something I can do to make this work in Firefox? Thanks

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about ruby-on-rails