I’m attempting to track down a javascript exception I’m getting when parsing some JSON in IE that has been returned by an AJAX request. Normally I’d assume a JSON formatting error somewhere in my code but in this case the JSON parses fine in Chrome, FireFox & IE but in IE’s case ONLY if the URL is localhost. If I change the URL to my-laptop instead, which points to exactly the same location, the JSON fails to parse in IE but is still ok in Chrome and FireFox.
The JSON is very simple. The line below is from VS.Net’s debugger so the double quotes on the ends are cosmetic:
data = "{ "ID" : 15, "Name" : "Hobart" } "
The JSON is being parsed with:
data = JSON.parse(data);
I’ve checked everything I can think of to see if the response is different between the response from localhost and my-laptop but can’t spot anything. Why would IE decide not to parse the JSON when the server hostname changes?
Update: If I open up the localhost version with IE’s compatibility mode switched on then the JSON paring alsi fails. Turn off compatibility mode and it works.
The cause of the issue is down to IE’s compatibility mode. The comments in this question led me to open up the IE Developer Tools window and the web app was running in IE7 compatibility mode. I don’t know why it was doing that and the compatibility mode button is not showing up in the IE address bar. Still at least I know what the problem is now and it’s a more tractable problem to resolve than debugging reams of javascript.