Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.parseJSON not working in Internet Explorer 10

$.parseJSON is working great in Firefox, Chrome, and Safari using the code below. However, in Internet Explorer 10, the script fails to yield a valid object.

Here's the jsFiddle: http://jsfiddle.net/gahathat/sq6Lb/

And the js code:

string = '{"result":"success"}';
$('#json_string').text(string);
item = $.parseJSON(string);
$('#json_result').text(item.result);

Is there a workaround for Internet Explorer that would correct this error?

like image 672
ams Avatar asked Dec 16 '22 08:12

ams


1 Answers

This should work:

$(function() {
    var string = '{"result":"success"}';

    $('#json_string').text(string);

    var item = $.parseJSON(string);
    $('#json_result').text(item.result);
});

IE has a global object called 'item' which can't be overwritten.

like image 121
sabof Avatar answered Dec 17 '22 20:12

sabof