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.
This commit is contained in:
parent
3f648c4e3a
commit
ff3645ee05
1 changed files with 4 additions and 2 deletions
|
@ -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))();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue