JSON undefined in IE7

I am using the following line of jQuery code:

$.get('/ajax/buy', {'categoryname':chosenSelected}, function(data) { data = JSON.parse(data); ... 

However, when running on IE7, I get this error message: JSON undefined:

How can I use a parser compatible with IE7 (and all major browsers)?

+6
json javascript jquery internet-explorer-7
source share
3 answers

You can use parseJSON available in jQuery.

+11
source share

You do not need to manually parse JSON. You can use the getJSON function:

 $.getJSON('/ajax/buy', { 'categoryname' : chosenSelected }, function(data) { // data will be already a parsed JSON object }); 

The parse method you are trying to call is available in the json2 library.

+7
source share

You need to add a JSON parser. In older browsers this is not included.

1 - Go to the repository: https://github.com/douglascrockford/JSON-js/

2 - Download and enable json2.js to your website or application.

That's all.

+1
source share

All Articles