MCPcopy Create free account
hub / github.com/components/jquery / ajaxHandleResponses

Function ajaxHandleResponses

jquery.js:8049–8102  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

8047 * - returns the corresponding response
8048 */
8049function ajaxHandleResponses( s, jqXHR, responses ) {
8050
8051 var ct, type, finalDataType, firstDataType,
8052 contents = s.contents,
8053 dataTypes = s.dataTypes;
8054
8055 // Remove auto dataType and get content-type in the process
8056 while ( dataTypes[ 0 ] === "*" ) {
8057 dataTypes.shift();
8058 if ( ct === undefined ) {
8059 ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
8060 }
8061 }
8062
8063 // Check if we're dealing with a known content-type
8064 if ( ct ) {
8065 for ( type in contents ) {
8066 if ( contents[ type ] && contents[ type ].test( ct ) ) {
8067 dataTypes.unshift( type );
8068 break;
8069 }
8070 }
8071 }
8072
8073 // Check to see if we have a response for the expected dataType
8074 if ( dataTypes[ 0 ] in responses ) {
8075 finalDataType = dataTypes[ 0 ];
8076 } else {
8077
8078 // Try convertible dataTypes
8079 for ( type in responses ) {
8080 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
8081 finalDataType = type;
8082 break;
8083 }
8084 if ( !firstDataType ) {
8085 firstDataType = type;
8086 }
8087 }
8088
8089 // Or just use first one
8090 finalDataType = finalDataType || firstDataType;
8091 }
8092
8093 // If we found a dataType
8094 // We add the dataType to the list if needed
8095 // and return the corresponding response
8096 if ( finalDataType ) {
8097 if ( finalDataType !== dataTypes[ 0 ] ) {
8098 dataTypes.unshift( finalDataType );
8099 }
8100 return responses[ finalDataType ];
8101 }
8102}
8103
8104/* Chain conversions given the request and the original response
8105 * Also sets the responseXXX fields on the jqXHR instance

Callers 1

doneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected