JSON Open or Save Issue on Internet Explorer

By | May 23, 2014

Have your Internet Explorer gave you a ‘JSON’ is undefined error? Have you ever encountered this Open or Save Issue on Internet Explorer when your trying to return a JSON Result?  Then your not alone, I had the similar issue I faced just recently where everything work in other browsers except for Internet Explorer.

At first Internet Explorer will pop-up Webpage Error like this, where it says Line: xxx Error: ‘JSON’ is undefined

2014-05-23 08_29_32-Webpage Error

Then when you click on no you dont want to debug it then another question pops up which says “Do you want to open or save {YourControllersActionName}{someRandom Alpha Numeric}.json (999 bytes) from yoururl.com?”

2014-05-22 15_36_36-Home - Internet Explorer

I’ve been trying different suggestions by returning the result to contentType as “application/json; charset=UTF-8” and contentEncoding as “UTF-8”.  Some even offered to return it as “text/plain” well that does not work as it will give me the JSON result on text displayed on my browser but don’t worry if you have a similar scenario then I have a solution for you.

On the first place why does this happen? This is because IE 11 has Java built in so it’s not recognizing the JSON file that you’re trying to return, having said that when your environment is on the intranet IE defaults to compatibility mode, you can check that yourself by going to developer tools in IE by pressing F12 and see what’s the default.

2014-05-23 09_37_41-F12

To resolve that all you need to do is to make sure you start with this doctype

<!DOCTYPE html>

And replace the default Meta Tag created by Visual Studio when you create a new MVC project, you need to change the default to Edge.

<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" />

Now it should work, to see how it looks before it was like this

2014-05-23 09_23_49-ContactSearch - Microsoft Visual Studio (Administrator)

with the change it will be like this

2014-05-23 09_24_48-ContactSearch - Microsoft Visual Studio (Administrator)


and now if you press F12 again Edge would be the default.

2014-05-23 09_39_44-F12

Leave a Reply