Commit ef86694a authored by jaubourg's avatar jaubourg

Renames determineDataType as determineResponse. Makes it more generic as a...

Renames determineDataType as determineResponse. Makes it more generic as a first step into integrating the logic into the main ajax done callback. Also fixes some comments in ajax/xhr.js.
parent 3e1d3d0f
...@@ -235,7 +235,7 @@ jQuery.extend({ ...@@ -235,7 +235,7 @@ jQuery.extend({
// Utility function that handles dataType when response is received // Utility function that handles dataType when response is received
// (for those transports that can give text or xml responses) // (for those transports that can give text or xml responses)
determineDataType: function( ct , text , xml ) { determineResponse: function( responses , ct ) {
var s = this, var s = this,
contents = s.contents, contents = s.contents,
...@@ -246,7 +246,7 @@ jQuery.extend({ ...@@ -246,7 +246,7 @@ jQuery.extend({
response; response;
// Auto (xml, json, script or text determined given headers) // Auto (xml, json, script or text determined given headers)
if ( transportDataType === "*" ) { if ( ct && transportDataType === "*" ) {
for ( type in contents ) { for ( type in contents ) {
if ( ( regexp = contents[ type ] ) && regexp.test( ct ) ) { if ( ( regexp = contents[ type ] ) && regexp.test( ct ) ) {
...@@ -256,23 +256,22 @@ jQuery.extend({ ...@@ -256,23 +256,22 @@ jQuery.extend({
} }
} }
// xml and parsed as such // Get response
if ( transportDataType === "xml" && for( type in responses ) {
xml && if ( type === transportDataType ) {
xml.documentElement /* #4958 */ ) { break;
}
response = xml; }
// Text response was provided
} else {
response = text; // Get final response
response = responses[ type ];
// If it's not really text, defer to converters // If it's not the right dataType, handle the dataTypeList
if ( transportDataType !== "text" ) { if ( transportDataType !== type ) {
dataTypes.unshift( "text" ); if ( transportDataType === "*" ) {
dataTypes.shift();
} }
dataTypes.unshift( type );
} }
return response; return response;
......
...@@ -12,8 +12,8 @@ var // Next active xhr id ...@@ -12,8 +12,8 @@ var // Next active xhr id
// XHR used to determine supports properties // XHR used to determine supports properties
testXHR; testXHR;
// Create the request object; Microsoft failed to properly // Create the request object
// (This is still attached to ajaxSettings for backward compatibility reasons) // (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xhr = window.ActiveXObject ? jQuery.ajaxSettings.xhr = window.ActiveXObject ?
/* Microsoft failed to properly /* Microsoft failed to properly
* implement the XMLHttpRequest in IE7 (can't request local files), * implement the XMLHttpRequest in IE7 (can't request local files),
...@@ -146,8 +146,9 @@ if ( jQuery.support.ajax ) { ...@@ -146,8 +146,9 @@ if ( jQuery.support.ajax ) {
// Get info // Get info
var status = xhr.status, var status = xhr.status,
statusText, 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 try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
...@@ -184,15 +185,15 @@ if ( jQuery.support.ajax ) { ...@@ -184,15 +185,15 @@ if ( jQuery.support.ajax ) {
status status
); );
// Guess response & update dataType accordingly // Construct response list
response = if ( xml && xml.documentElement /* #4958 */ ) {
s.determineDataType( responses.xml = xml;
xhr.getResponseHeader("content-type"), }
xhr.responseText, responses.text = xhr.responseText;
xhr.responseXML );
// Call complete // Call complete
complete(status,statusText,response,responseHeaders); complete(status,statusText,s.determineResponse( responses,
xhr.getResponseHeader( "content-type" ) ),responseHeaders);
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment