// Utility function that handles dataType when response is received
// (for those transports that can give text or xml responses)
- determineDataType: function( ct , text , xml ) {
+ determineResponse: function( responses , ct ) {
var s = this,
contents = s.contents,
response;
// Auto (xml, json, script or text determined given headers)
- if ( transportDataType === "*" ) {
+ if ( ct && transportDataType === "*" ) {
for ( type in contents ) {
if ( ( regexp = contents[ type ] ) && regexp.test( ct ) ) {
}
}
- // xml and parsed as such
- if ( transportDataType === "xml" &&
- xml &&
- xml.documentElement /* #4958 */ ) {
-
- response = xml;
-
- // Text response was provided
- } else {
+ // Get response
+ for( type in responses ) {
+ if ( type === transportDataType ) {
+ break;
+ }
+ }
- response = text;
+ // Get final response
+ response = responses[ type ];
- // If it's not really text, defer to converters
- if ( transportDataType !== "text" ) {
- dataTypes.unshift( "text" );
+ // If it's not the right dataType, handle the dataTypeList
+ if ( transportDataType !== type ) {
+ if ( transportDataType === "*" ) {
+ dataTypes.shift();
}
-
+ dataTypes.unshift( type );
}
return response;
// XHR used to determine supports properties
testXHR;
-// Create the request object; Microsoft failed to properly
-// (This is still attached to ajaxSettings for backward compatibility reasons)
+// Create the request object
+// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xhr = window.ActiveXObject ?
/* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files),
// Get info
var status = xhr.status,
statusText,
- response,
- responseHeaders = xhr.getAllResponseHeaders();
+ responseHeaders = xhr.getAllResponseHeaders(),
+ responses = {},
+ xml = xhr.responseXML;
try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
status
);
- // Guess response & update dataType accordingly
- response =
- s.determineDataType(
- xhr.getResponseHeader("content-type"),
- xhr.responseText,
- xhr.responseXML );
+ // Construct response list
+ if ( xml && xml.documentElement /* #4958 */ ) {
+ responses.xml = xml;
+ }
+ responses.text = xhr.responseText;
// Call complete
- complete(status,statusText,response,responseHeaders);
+ complete(status,statusText,s.determineResponse( responses,
+ xhr.getResponseHeader( "content-type" ) ),responseHeaders);
}
}
};