T. Cem Yılmaz
T. Cem Yılmaz

Reputation: 510

Internet explorer 9 gives parseJSON error

I don't know if it's caused by jQuery or by my script. This is where internet explorer 9 gives error:

parseJSON: function( data ) {
    // Attempt to parse using the native JSON parser first
    if ( window.JSON && window.JSON.parse ) {
        return window.JSON.parse( data ); <<< this the "Invalid Character" err.
    }

This is my javascript code

http://jsfiddle.net/fNPwh

From my research I also checked out my DOCTYPE here it is. They were talking about Quirks mode so I also tried to put x-ua-compatible but nothing changed

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" > <!-- IE9 mode -->
blabla

Why ie9 gives jQuery's invalid character error? and not the firefox or webkit. Oh by the way I am using jQuery 1.9.1.

Upvotes: 2

Views: 5773

Answers (1)

cameronjchurch
cameronjchurch

Reputation: 410

This appears to be a bug in the jQuery library. This post contains code to add/modify for the fix. Basically just move the check for null before the attempt to parse and add a check for undefined. The start of the method should then look like this...

parseJSON: function( data ) {
    if (data === undefined) {
        return data;
    }
    if (data === null) {
        return data;
    }

    // Attempt to parse using the native JSON parser first
    if ( window.JSON && window.JSON.parse ) {
        return window.JSON.parse( data );
    }
...

I've verified this fix in IE10 and Chrome.

Upvotes: 1

Related Questions