51

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?

Dalen
  • 8,856
  • 4
  • 47
  • 52
ajm
  • 12,863
  • 58
  • 163
  • 234
  • 8
    Have you checked that they're not running IE8 in IE7-compatibility mode? (open the Dev Tools [F12], then check the toolbar to see the browser mode) – Spudley Mar 17 '11 at 12:55
  • The settings we changed are in IE, go to TOOLs->Internet Options-> Advanced -> Security Enable Smart Screen filters, Use SSL 3.0 and use TLS 1.0. – ajm Mar 17 '11 at 12:56
  • @Spudley Its hard to tell in some case it works and in rarest case it does not work. We are also not able to replicate the issue frequently so actual cause is still unknown to us. Sorry, I know this information is not helping. – ajm Mar 17 '11 at 13:00
  • Disable DivX addons and see if it helps. –  Mar 19 '11 at 20:41
  • 1
    "Have you checked that they're not running IE8 in IE7-compatibility mode? (open the Dev Tools [F12], then check the toolbar to see the browser mode) – Spudley Mar 17 '11 at 12:55" **Spudley - that fixed it for me. Many thanks.** –  Mar 04 '12 at 20:28
  • http://stackoverflow.com/questions/4715373/json-not-defined-internet-explorer-8 there is related question. It helped me so much. – gis_wild Apr 27 '12 at 12:34

7 Answers7

67

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: JSON on IE6 (IE7)

UPDATE

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

Community
  • 1
  • 1
Dalen
  • 8,856
  • 4
  • 47
  • 52
  • @DalenWe are not specifically using JSON. Its being used by the Jquery plugin we are using. – ajm Mar 17 '11 at 13:02
  • 1
    still you need to include that json2.js, whenever you use something like JSON.stringify you need json2.js. If it is not a problem of including json2 submit your file here: http://closure-compiler.appspot.com/home, the google closure compiler will tell you if there are any errors or warning in your code – Dalen Mar 17 '11 at 13:09
  • @Dalen I checked the URL http://closure-compiler.appspot.com/home and submitted my code to it but it does not give any erros or warnings in both IE and Firefox. I have no problem in including jason2.js in my application but then how do I check if its working or not as I am not able to replicate the issue itself? :( – ajm Mar 17 '11 at 13:21
  • 3
    If you are facing my same problem, you'll find him on IE7 or IE8 compatibility mode – Dalen Mar 17 '11 at 13:24
21
<!DOCTYPE html>

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

<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
Drew Chapin
  • 7,779
  • 5
  • 58
  • 84
marvwhere
  • 561
  • 3
  • 11
  • 1
    Also you can't use jQuery 2.0 or above with IE regardless of JSON or compatibility modes. – D-Mac Nov 08 '13 at 22:45
  • 2
    @D-Mac You meant IE < 9. jQuery didn't just drop support fot IE altogether. – ZenMaster Dec 07 '13 at 02:42
  • 1
    The second code snippet (X-UA-Compatible) serves to explicitly disable IE's Compatibility View for the page (even if the site is added to the Compatibility View list). See http://msdn.microsoft.com/en-us/library/jj676915%28v=vs.85%29.aspx – David Dec 31 '13 at 21:06
7

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.

Sirko
  • 72,589
  • 19
  • 149
  • 183
Kainattu
  • 81
  • 2
  • 6
6

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

Alex
  • 7,320
  • 1
  • 18
  • 31
3

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

Sunil
  • 2,885
  • 5
  • 34
  • 41
0

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>
Stefan Michev
  • 4,795
  • 3
  • 35
  • 30
-1

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
    });
Travis Heeter
  • 13,002
  • 13
  • 87
  • 129