admin管理员组

文章数量:1335138

$.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: /

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?

$.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/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?

Share Improve this question asked Jul 20, 2013 at 20:02 amsams 1738 bronze badges 5
  • Which version of jQuery are you using? – Steven V Commented Jul 20, 2013 at 20:07
  • Did you only try it with jsFiddle? The error I get from IE9 is related to iframes. – sabof Commented Jul 20, 2013 at 20:11
  • I get the same error on my domain as well. – ams Commented Jul 20, 2013 at 20:14
  • I see the error '$' is undefined in the IE10 console when opening the fiddle. – Mooseman Commented Jul 20, 2013 at 20:16
  • And I've tried jQuery 1.9.1 and 2.0.2 – ams Commented Jul 20, 2013 at 20:16
Add a ment  | 

1 Answer 1

Reset to default 12

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.

本文标签: javascriptparseJSON not working in Internet Explorer 10Stack Overflow