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

Function ajaxHandleResponses

2.1.1/src/ajax.js:142–193  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

140 * - returns the corresponding response
141 */
142function ajaxHandleResponses( s, jqXHR, responses ) {
143
144 var ct, type, finalDataType, firstDataType,
145 contents = s.contents,
146 dataTypes = s.dataTypes;
147
148 // Remove auto dataType and get content-type in the process
149 while ( dataTypes[ 0 ] === "*" ) {
150 dataTypes.shift();
151 if ( ct === undefined ) {
152 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
153 }
154 }
155
156 // Check if we're dealing with a known content-type
157 if ( ct ) {
158 for ( type in contents ) {
159 if ( contents[ type ] && contents[ type ].test( ct ) ) {
160 dataTypes.unshift( type );
161 break;
162 }
163 }
164 }
165
166 // Check to see if we have a response for the expected dataType
167 if ( dataTypes[ 0 ] in responses ) {
168 finalDataType = dataTypes[ 0 ];
169 } else {
170 // Try convertible dataTypes
171 for ( type in responses ) {
172 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
173 finalDataType = type;
174 break;
175 }
176 if ( !firstDataType ) {
177 firstDataType = type;
178 }
179 }
180 // Or just use first one
181 finalDataType = finalDataType || firstDataType;
182 }
183
184 // If we found a dataType
185 // We add the dataType to the list if needed
186 // and return the corresponding response
187 if ( finalDataType ) {
188 if ( finalDataType !== dataTypes[ 0 ] ) {
189 dataTypes.unshift( finalDataType );
190 }
191 return responses[ finalDataType ];
192 }
193}
194
195/* Chain conversions given the request and the original response
196 * Also sets the responseXXX fields on the jqXHR instance

Callers 1

doneFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected