- // Get the JavaScript object, if JSON is used.
- if ( type == "json" )
- data = eval("(" + data + ")");
+ // If the type is "script", eval it in global context
+ if ( type === "script" ) {
+ jQuery.globalEval( data );
+ }
+
+ // Get the JavaScript object, if JSON is used.
+ if ( type == "json" ) {
+ if ( typeof JSON === "object" && JSON.parse ) {
+ data = JSON.parse( data );
+ } else {
+ data = (new Function("return " + data))();
+ }
+ }
+ }