Skip to main content

Bug Tracker

Side navigation

Ticket #2639: detect_content_type.diff


File detect_content_type.diff, 0.7 KB (added by Shaft0rz, April 02, 2008 06:43PM UTC)

diff that implements auto content-type detection

Index: jquery/src/ajax.js
===================================================================
@@ -449,13 +449,14 @@
 
 		if ( xml && data.documentElement.tagName == "parsererror" )
 			throw "parsererror";
-
+		
+		// If no specific type is given, use Content-Type as a clue
 		// If the type is "script", eval it in global context
-		if ( type == "script" )
+		if ( type == "script" || (!type && (ct == "application/javascript" || ct == "text/javascript" || ct == "text/ecmascript" || ct == "application/ecmascript")))
 			jQuery.globalEval( data );
 
 		// Get the JavaScript object, if JSON is used.
-		if ( type == "json" )
+		if ( type == "json" || (!type && ct == "application/json"))
 			data = eval("(" + data + ")");
 
 		return data;

Download in other formats:

Original Format