X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax.js;h=4db08a4dcab62bf82af503bd3315e7ff527c3c6b;hb=90a87c03b4943d75c24bc5e6246630231d12d933;hp=bffbeb607e66ddaba235968d7442314c2cb9f88f;hpb=a0451f162e95b552f9dc307b8529c114edeab417;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index bffbeb6..4db08a4 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -481,24 +481,32 @@ jQuery.extend({ xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0, data = xml ? xhr.responseXML : xhr.responseText; - if ( xml && data.documentElement.tagName == "parsererror" ) + if ( xml && data.documentElement.tagName == "parsererror" ) { throw "parsererror"; + } // Allow a pre-filtering function to sanitize the response // s != null is checked to keep backwards compatibility - if( s && s.dataFilter ) + if ( s && s.dataFilter ) { data = s.dataFilter( data, type ); + } // The filter can actually parse the response - if( typeof data === "string" ){ + if ( typeof data === "string" ) { // If the type is "script", eval it in global context - if ( type == "script" ) + if ( type === "script" ) { jQuery.globalEval( data ); + } // Get the JavaScript object, if JSON is used. - if ( type == "json" ) - data = window["eval"]("(" + data + ")"); + if ( type == "json" ) { + if ( typeof JSON === "object" && JSON.parse ) { + data = JSON.parse( data ); + } else { + data = (new Function("return " + data))(); + } + } } return data;