MCPcopy Create free account
hub / github.com/TruthHun/BookStack / ajaxHandleResponses

Function ajaxHandleResponses

static/jquery/1.12.4/jquery.js:9198–9250  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

9196 * - returns the corresponding response
9197 */
9198function ajaxHandleResponses( s, jqXHR, responses ) {
9199 var firstDataType, ct, finalDataType, type,
9200 contents = s.contents,
9201 dataTypes = s.dataTypes;
9202
9203 // Remove auto dataType and get content-type in the process
9204 while ( dataTypes[ 0 ] === "*" ) {
9205 dataTypes.shift();
9206 if ( ct === undefined ) {
9207 ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
9208 }
9209 }
9210
9211 // Check if we're dealing with a known content-type
9212 if ( ct ) {
9213 for ( type in contents ) {
9214 if ( contents[ type ] && contents[ type ].test( ct ) ) {
9215 dataTypes.unshift( type );
9216 break;
9217 }
9218 }
9219 }
9220
9221 // Check to see if we have a response for the expected dataType
9222 if ( dataTypes[ 0 ] in responses ) {
9223 finalDataType = dataTypes[ 0 ];
9224 } else {
9225
9226 // Try convertible dataTypes
9227 for ( type in responses ) {
9228 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
9229 finalDataType = type;
9230 break;
9231 }
9232 if ( !firstDataType ) {
9233 firstDataType = type;
9234 }
9235 }
9236
9237 // Or just use first one
9238 finalDataType = finalDataType || firstDataType;
9239 }
9240
9241 // If we found a dataType
9242 // We add the dataType to the list if needed
9243 // and return the corresponding response
9244 if ( finalDataType ) {
9245 if ( finalDataType !== dataTypes[ 0 ] ) {
9246 dataTypes.unshift( finalDataType );
9247 }
9248 return responses[ finalDataType ];
9249 }
9250}
9251
9252/* Chain conversions given the request and the original response
9253 * Also sets the responseXXX fields on the jqXHR instance

Callers 1

doneFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected