'JSON' is undefined error in JavaScript in Internet Explorer

JavascriptJqueryJsonInternet Explorer

Javascript Problem Overview


We are using jQuery in our application. We have used a jQuery plugin to implement JavaScript session.

It is working properly in Firefox and most Internet Explorer 8 browsers.

But in some Internet Explorer 8 browsers it does not work. It gives the following error.

Message: 'JSON' is undefined
Line: 6
Char: 3
Code: 0


Message: '$.namesession' is null or not an object
Line: 53
Char: 2
Code: 0

`

The version of Internet Explorer in both the cases is same.

But there were some differences in Internet Explorer settings like Use SSL3.0 and Enable Smart Screen filters check boxes in the Advanced tab in the Internet options were unchecked.

When we checked it, it started working. When we unchecked them it was still working.

What is the actual problem in IE8?

Javascript Solutions


Solution 1 - Javascript

Maybe it is not what you are looking for, but I had a similar problem and i solved it including JSON 2 to my application:

https://github.com/douglascrockford/JSON-js

Other browsers natively implements JSON but IE < 8 (also IE 8 compatibility mode) does not, that's why you need to include it.

Here is a related question: https://stackoverflow.com/questions/2503175/json-on-ie6-ie7

UPDATE

the JSON parser has been updated so you should use the new one: http://bestiejs.github.io/json3/

Solution 2 - Javascript

<!DOCTYPE html>

Otherwise IE8 is not acting right. Also you should use:

<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />

Solution 3 - Javascript

Please add json2.js in your project . i was faced the same issue i have fixed.

please use the link: https://raw.github.com/douglascrockford/JSON-js/master/json2.js and create new file json.js, copy the page and past into newly created file , and move that file into your web application.

I hope it will work.

Solution 4 - Javascript

Check for extra commas in your JSON response. If the last element of an array has a comma, this will break in IE

Solution 5 - Javascript

Change the content type to 'application/x-www-form-urlencoded'

Solution 6 - Javascript

I had the very same problem recently. In my case on the top of a php script I had some code generationg obviously some extra output to the browser. Removal of empty lines (between ?> and html-tag ) and simple cleanup helped me out:

<?php 
include('../config.php');

//

ob_clean();
?>
<!DOCTYPE html>

Solution 7 - Javascript

I had this error 2 times. Each time it was solved by changing the ajax type. Either GET to POST or POST to GET.

$.ajax({
		type:'GET', // or 'POST'
		url: "file.cfm?action=get_table&varb=" + varb
	});

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionashishjmeshramView Question on Stackoverflow
Solution 1 - JavascriptDalenView Answer on Stackoverflow
Solution 2 - JavascriptmarvwhereView Answer on Stackoverflow
Solution 3 - JavascriptKainattuView Answer on Stackoverflow
Solution 4 - JavascriptAlexView Answer on Stackoverflow
Solution 5 - JavascriptSunilView Answer on Stackoverflow
Solution 6 - JavascriptStefan MichevView Answer on Stackoverflow
Solution 7 - JavascriptTravis HeeterView Answer on Stackoverflow