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

Function ajaxHandleResponses

static/wangEditor/js/lib/jquery-2.2.1.js:8108–8161  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

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

Callers 1

doneFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected