views:

827

answers:

4

Hi

For one of our ajax request (with a .json response) some of our clients have complained that they are seeing a "File Download" prompt asking the user to download the .json response. I am baffled because considering that this is an xhr response, this should never happen. Has anyone seen this?

Thanks

+3  A: 

try specifying a MIME type of "text/plain" in the response. or just drop the ".json" extension from the url (try .txt, or .js, for instance)

Here Be Wolves
A: 

Hmm. But this is an ajax respone. Why would it open a "Download Box" for an ajax response.

Use comments, not answers, to ask questions about the original question or specific answers.
strager
A: 

Drop the .json and set the content type as text/html. IE doesn't know what type of file you are sending it, so it offers to download. It knows what to do with text/html :)

No. Don't serve json as text/html. http://jibbering.com/blog/?p=514
Cheeso
+3  A: 

Hi,

Not sure if you found a solution, but I had a similar problem where IE tried to download any JS responses. To fix it, I had to ensure that format.html appears above format.js in the response block:

def index

  # ...

  respond_to do |format|
    # html must be above js, otherwise IE will try to download the JS
    format.html
    format.js
  end
end

Hope this helps.

Chris
This solution worked for me. No idea why (other browsers worked fine).
Kyle Fox
IE Accept header: `Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, */*`Firefox Accept header: `Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8`Not sure what the q= means yet, but i bet it has something to do with how much it wants content of that particular type.
Peter Kovacs