First off, please understand that I am not trying to view JSON in IE9. I use Fiddler all the time. I have a third party uploader called Fine Uploader that expects JSON response messages upon successful Ajax file uploads.
Now I understand that IE9 does not have a MIME to display JSON but I am NOT trying to display JSON. I am just returning a JSON response after ajax uploading some files and IE9 attempts to open my ajax response.
Since I intend to have all my Web API responses formatted in JSON do I have to add a custom text/html response content-type for every api call to make my application compatible with IE9? Seriously ridiculous stuff, I can't get over how much time I waste dealing with IE compatibility issues.
Cross-platform to open JSON files: Generally, users can open the JSON file in any text editor as it is a plain text-based file. The Google Chrome and Mozilla Firefox web browsers are cross-platform to open JSON files that are compatible with every operating system (OS).
Although Ray's answer works, this changes the response content type for all Json respones. Ideally, we shouldn't affect the response type for browsers which play nicely.
For an easy way to resolve this (particularly in MVC) see my answer to this question.
In short, the following code does the trick, and can be wrapped into a base controller / helper method if applicable:
if (!Request.AcceptTypes.Contains("application/json"))
return base.Json(data, "text/plain");
else
return base.Json(data);
I hope that helps someone else!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With