MCPcopy Create free account
hub / github.com/shipshapecode/tether / ajaxHandleResponses

Function ajaxHandleResponses

docs/welcome/js/jquery.js:8117–8175  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

8115 * - returns the corresponding response
8116 */
8117function ajaxHandleResponses( s, jqXHR, responses ) {
8118 var firstDataType, ct, finalDataType, type,
8119 contents = s.contents,
8120 dataTypes = s.dataTypes,
8121 responseFields = s.responseFields;
8122
8123 // Fill responseXXX fields
8124 for ( type in responseFields ) {
8125 if ( type in responses ) {
8126 jqXHR[ responseFields[type] ] = responses[ type ];
8127 }
8128 }
8129
8130 // Remove auto dataType and get content-type in the process
8131 while( dataTypes[ 0 ] === "*" ) {
8132 dataTypes.shift();
8133 if ( ct === undefined ) {
8134 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
8135 }
8136 }
8137
8138 // Check if we're dealing with a known content-type
8139 if ( ct ) {
8140 for ( type in contents ) {
8141 if ( contents[ type ] && contents[ type ].test( ct ) ) {
8142 dataTypes.unshift( type );
8143 break;
8144 }
8145 }
8146 }
8147
8148 // Check to see if we have a response for the expected dataType
8149 if ( dataTypes[ 0 ] in responses ) {
8150 finalDataType = dataTypes[ 0 ];
8151 } else {
8152 // Try convertible dataTypes
8153 for ( type in responses ) {
8154 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
8155 finalDataType = type;
8156 break;
8157 }
8158 if ( !firstDataType ) {
8159 firstDataType = type;
8160 }
8161 }
8162 // Or just use first one
8163 finalDataType = finalDataType || firstDataType;
8164 }
8165
8166 // If we found a dataType
8167 // We add the dataType to the list if needed
8168 // and return the corresponding response
8169 if ( finalDataType ) {
8170 if ( finalDataType !== dataTypes[ 0 ] ) {
8171 dataTypes.unshift( finalDataType );
8172 }
8173 return responses[ finalDataType ];
8174 }

Callers 1

doneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…