0

My searching leads me to believe this is an issue with the headers being set for the response. This application is built using the Zend framework, and here are the headers being set (this response contains information about a file upload):

$response
    ->setHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT')
    ->setHeader('Cache-Control', 'private, no-cache')
    ->setHeader('Pragma', 'no-cache')
    ->setHeader('Content-Disposition', 'inline; filename="files.json"')
    ->setHeader('X-Content-Type-Options', 'nosniff')
    ->setHeader('Content-type', 'application/json; charset=UTF-8');

This is the contents of the "files.json": {"webpath":"http://www.domain.com/avatar/38b/3ef/f8b/a4c62a71.jpg","file_id":"484","height":250,"width":250}

Edit: I'm having this issue in all versions of IE, including IE9. I have also attempted to use 'text/plain' for the Content-type, with no avail. Also fixed the typo on the word "private".

velocityhead
  • 172
  • 7
  • 3
    `Content-Disposition` would be the header that controls it. Since it's set to `inline` you're doing nothing wrong. Moral of the story? `!@#$ IE.` – Matt Ball Dec 15 '11 at 18:24
  • 3
    I'm pretty sure `priave` should read `private` (not that this should affect it) - and try setting a `Content-Type` of `text/plain`, it is unlikely the JSON consumer needs the correct content type and IE has a habit of popping a download box for content types it doesn't recognize. – DaveRandom Dec 15 '11 at 18:24
  • what version of IE, or all versions? browser inconsistencies require specificity to hunt down. – Francis Yaconiello Dec 15 '11 at 18:41
  • I have this issue with all version of IE, but I'm currently testing with IE9. I have also tried setting the Content-type to "text/plain" but IE still wants to download the file. – velocityhead Dec 15 '11 at 19:18
  • ZF will happily send the same header fields multiple times without error even if they contain different values. Can you confirm that the header received is the same as the supposedly sent? – Richard Ayotte Dec 15 '11 at 23:35
  • What does "work as expected" specifically mean? What *is* expected? In your question you only write that you not expect it to download. Is that so? Why not? What else? – hakre Dec 16 '11 at 15:07
  • I had the same problem in C# / jQuery and wrote a blog post where some other suggestions have been added: http://blog.degree.no/2012/09/jquery-json-ie8ie9-treats-response-as-downloadable-file/ – Andreas Oct 01 '12 at 13:27
  • possible duplicate of [Json response download in IE(7~10)](http://stackoverflow.com/questions/13943439/json-response-download-in-ie710) – Joe Apr 25 '13 at 15:41
  • **here it is already answered** ["IE and JSON"][1] [1]: http://stackoverflow.com/questions/2483771/how-can-i-convince-ie-to-simply-display-application-json-rather-than-offer-to-do – Sundara Prabu Aug 07 '14 at 09:22

4 Answers4

0

Have you tried setting Content-Disposition to just "inline" (i.e. remove '; filename="files.json"')?

Max Nanasy
  • 5,871
  • 7
  • 33
  • 38
0

When I am returning json I set the following in whateverAction():-

$this->getResponse()->setHttpResponseCode(200);
$this->getResponse()->setHeader('Content-Type', 'application/json');
$this->getResponse()->setBody($Json());

That's it, nothing else and it works across all browsers. All those I can test anyway, which includes IE 9.

vascowhite
  • 18,120
  • 9
  • 61
  • 77
0

If browsers ask you to download a JSON document nothing goes wrong. By default browsers do not display JSON which has a proper content type inline unless you have some extension installed (e.g. JSONView in Firefox).

If you just want to view the JSON created by your script, use such an extension or temporarily use a text content type (such as text/plain or text/javascript). In other cases leave it as-is since JSON should be sent with a proper content type.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
-2

The headers tell IE to download the file. I would remove

->setHeader('Content-Disposition', 'inline; filename="files.json"')

because I think this one triggers the download.

If that's not the case, I would remove all headers at first, then review if they are all written properly (see "private") and test first with no headers and then adding them one by one to find out which one triggers your problem. Then please write which one it is to look further into it.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • 1
    Nope. `Content-Disposition: attachment` is what tells the browser to download the file. – Matt Ball Dec 15 '11 at 18:32
  • Well place your bet which one triggers it. I wrote I think it does, right now I have no IE here to test for it, but at a first glance I would pick that one. Just trying to be helpful here. – hakre Dec 15 '11 at 18:35