From: jeresig Date: Tue, 5 Jan 2010 22:33:41 +0000 (-0500) Subject: Try to use the native JSON parser in all cases and fallback to the old technique... X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=ff3645ee05ca5cb416b7d3500a45a4410ce0470a;p=jquery.git 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. --- 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))(); } }