MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / ajaxHandleResponses

Function ajaxHandleResponses

test/bower_components/jquery/src/ajax.js:129–180  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

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

Callers 1

doneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected