Bug Tracker

Ticket #2639: detect_content_type.diff

File detect_content_type.diff, 744 bytes (added by Shaft0rz, 6 years ago)

diff that implements auto content-type detection

Line 
1Index: jquery/src/ajax.js
2===================================================================
3@@ -449,13 +449,14 @@
4 
5                if ( xml && data.documentElement.tagName == "parsererror" )
6                        throw "parsererror";
7-
8+               
9+               // If no specific type is given, use Content-Type as a clue
10                // If the type is "script", eval it in global context
11-               if ( type == "script" )
12+               if ( type == "script" || (!type && (ct == "application/javascript" || ct == "text/javascript" || ct == "text/ecmascript" || ct == "application/ecmascript")))
13                        jQuery.globalEval( data );
14 
15                // Get the JavaScript object, if JSON is used.
16-               if ( type == "json" )
17+               if ( type == "json" || (!type && ct == "application/json"))
18                        data = eval("(" + data + ")");
19 
20                return data;