MCPcopy Create free account
hub / github.com/JsAaron/jQuery / ajaxHandleResponses

Function ajaxHandleResponses

2.0.3/2.0.3.js:7583–7634  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

7581 * - returns the corresponding response
7582 */
7583 function ajaxHandleResponses( s, jqXHR, responses ) {
7584
7585 var ct, type, finalDataType, firstDataType,
7586 contents = s.contents,
7587 dataTypes = s.dataTypes;
7588
7589 // Remove auto dataType and get content-type in the process
7590 while( dataTypes[ 0 ] === "*" ) {
7591 dataTypes.shift();
7592 if ( ct === undefined ) {
7593 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
7594 }
7595 }
7596
7597 // Check if we're dealing with a known content-type
7598 if ( ct ) {
7599 for ( type in contents ) {
7600 if ( contents[ type ] && contents[ type ].test( ct ) ) {
7601 dataTypes.unshift( type );
7602 break;
7603 }
7604 }
7605 }
7606
7607 // Check to see if we have a response for the expected dataType
7608 if ( dataTypes[ 0 ] in responses ) {
7609 finalDataType = dataTypes[ 0 ];
7610 } else {
7611 // Try convertible dataTypes
7612 for ( type in responses ) {
7613 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
7614 finalDataType = type;
7615 break;
7616 }
7617 if ( !firstDataType ) {
7618 firstDataType = type;
7619 }
7620 }
7621 // Or just use first one
7622 finalDataType = finalDataType || firstDataType;
7623 }
7624
7625 // If we found a dataType
7626 // We add the dataType to the list if needed
7627 // and return the corresponding response
7628 if ( finalDataType ) {
7629 if ( finalDataType !== dataTypes[ 0 ] ) {
7630 dataTypes.unshift( finalDataType );
7631 }
7632 return responses[ finalDataType ];
7633 }
7634 }
7635
7636 /* Chain conversions given the request and the original response
7637 * Also sets the responseXXX fields on the jqXHR instance

Callers 1

doneFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected