diff options
author | jeresig <jeresig@gmail.com> | 2010-01-05 17:33:41 -0500 |
---|---|---|
committer | jeresig <jeresig@gmail.com> | 2010-01-05 17:33:41 -0500 |
commit | ff3645ee05ca5cb416b7d3500a45a4410ce0470a (patch) | |
tree | b2a2183ba3913c09be059c22c5b5f911855d2451 /src/ajax.js | |
parent | 3f648c4e3abe236b8ec6a19822313be794e5a9df (diff) | |
download | jquery-ff3645ee05ca5cb416b7d3500a45a4410ce0470a.tar.gz jquery-ff3645ee05ca5cb416b7d3500a45a4410ce0470a.zip |
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.
Diffstat (limited to 'src/ajax.js')
-rw-r--r-- | src/ajax.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/ajax.js b/src/ajax.js index b5adf2c7f..91519d289 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))(); } } |