I had a few JSON calls which IE8 was prompting me to download/save the response rather than simply hand it to jQuery to do it’s thing.
The returned JSON had the “correct” header and no other browsers were experiencing any issue:
header('Content-type: application/json'); |
To get around the IE8 issue, I had to change the header of the returned JSON to return text/plain:
header('Content-type: text/plain'); |
and ensure that my JSON calls had the dataType “json” specified. Without this explicitly specified, the browser was unable to parse the returned JSON.
$.ajax({ type: "POST", dataType: "json", url: URL, data:data, success: function(data){ alert(data.status) } }); |
Boom!
As an extra note, I was also using dropzone.js for drag and drop file uploads. Dropzone.js doesn’t allow you to force the datatype of the response so I had to convert the response to JSON before doing anything with it with:
JSON.parse(responseText); |
(Note, JSON.parse is only supported in modern browsers, this was not an issue though for me though as only modern browsers were able to use the dropzone functionality anyway and I had a fallback in place for older browsers)