return match || null;
},
+ // Overrides response content-type header
+ overrideMimeType: function( type ) {
+ if ( state === 0 ) {
+ s.mimeType = type;
+ }
+ return this;
+ },
+
// Cancel the request
abort: function( statusText ) {
statusText = statusText || "abort";
while( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
- ct = jqXHR.getResponseHeader( "content-type" );
+ ct = s.mimeType || jqXHR.getResponseHeader( "content-type" );
}
}
}
}
+ // Override mime type if needed
+ if ( s.mimeType && xhr.overrideMimeType ) {
+ xhr.overrideMimeType( s.mimeType );
+ }
+
// Requested-With header
// Not set for crossDomain requests with no content
// (see why at http://trac.dojotoolkit.org/ticket/9486)
});
+test("jQuery.ajax - overrideMimeType", function() {
+
+ expect( 2 );
+
+ stop();
+
+ jQuery.when(
+
+ jQuery.ajax( url("data/json.php") , {
+ beforeSend: function( xhr ) {
+ xhr.overrideMimeType( "application/json" );
+ },
+ success: function( json ) {
+ ok( json.data , "Mimetype overriden using beforeSend" );
+ }
+ }),
+
+ jQuery.ajax( url("data/json.php") , {
+ mimeType: "application/json",
+ success: function( json ) {
+ ok( json.data , "Mimetype overriden using mimeType option" );
+ }
+ })
+
+ ).then( start , start );
+
+});
+
test("jQuery.ajax - abort in prefilter", function() {
expect( 1 );