Currently I'm writing a JavaScript file and have the following line:
var res = "JSON=" + JSON.stringify(result);
result is being set just above this line. The issue I'm having is that IE8 (IE8 only, that is) is reporting to me that JSON is undefined somehow. I'm not sure what to make of this since, as I understood it, IE8 is a browser that implemented JSON support. Does anyone have any idea what might be going on?
Other things that absence of doctype or wrong doctype, or some error with html syntax, will force IE to use document modes different from what you expect.
I was using simple "" in a test document and the absence of TITLE tag as a child of HEAD tag made window.JSON become undefined.
Remember always that it's better to test the resource against the version of browser. And, if your users can use IE's with emulation of document modes, it's better you have a piece of code to provide the JSON.parse and JSON.stringify when natives are undefined.
In my case the undefined error was because I was missing a JSON library.
You can add JSON object like this (replace the relative path with your own path):
For json2 library: http://cdnjs.com/libraries/json2/
There is also a json3 library: http://cdnjs.com/libraries/json3/
Then you can refer to it in your code:
Check jQuery version. jQuery 2.0 drops support for IE 6, 7 and 8. Use jQuery 1.x instead, which is still officially supported. you can use this Code.
read more about jquery migrate.
if not working check this article.
Make sure you're actually in IE 8 mode by using the preferred method, a standards doctype...
...or the undesired method, the
X-UA-Compatible
meta tag/header...See Defining Document Compatibility for more information.
May happen despite
<!DOCTYPE html>
if the page encoding isUTF-8
withBOM
(byte order mark). Try saving the file asUTF-8
withoutBOM
, using a suitable text editor.