From ff3645ee05ca5cb416b7d3500a45a4410ce0470a Mon Sep 17 00:00:00 2001 From: jeresig Date: Tue, 5 Jan 2010 17:33:41 -0500 Subject: [PATCH] Try to use the native JSON parser in all cases and fallback to the old technique otherwise. This allows us to also handle cases where the JSON parser is unable to parse JSON-like strings correctly (e.g. {foo:bar}) which is something that worked before but would stop working with the switch to the new parser. --- src/ajax.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index b5adf2c..91519d2 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -579,9 +579,11 @@ jQuery.extend({ // Get the JavaScript object, if JSON is used. if ( type === "json" ) { - if ( typeof JSON === "object" && JSON.parse ) { + // Try to use the native JSON parser first + try { data = JSON.parse( data ); - } else { + + } catch(e) { data = (new Function("return " + data))(); } } -- 1.7.10.4