| 9253 | * Also sets the responseXXX fields on the jqXHR instance |
| 9254 | */ |
| 9255 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
| 9256 | var conv2, current, conv, tmp, prev, |
| 9257 | converters = {}, |
| 9258 | |
| 9259 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 9260 | dataTypes = s.dataTypes.slice(); |
| 9261 | |
| 9262 | // Create converters map with lowercased keys |
| 9263 | if ( dataTypes[ 1 ] ) { |
| 9264 | for ( conv in s.converters ) { |
| 9265 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
| 9266 | } |
| 9267 | } |
| 9268 | |
| 9269 | current = dataTypes.shift(); |
| 9270 | |
| 9271 | // Convert to each sequential dataType |
| 9272 | while ( current ) { |
| 9273 | |
| 9274 | if ( s.responseFields[ current ] ) { |
| 9275 | jqXHR[ s.responseFields[ current ] ] = response; |
| 9276 | } |
| 9277 | |
| 9278 | // Apply the dataFilter if provided |
| 9279 | if ( !prev && isSuccess && s.dataFilter ) { |
| 9280 | response = s.dataFilter( response, s.dataType ); |
| 9281 | } |
| 9282 | |
| 9283 | prev = current; |
| 9284 | current = dataTypes.shift(); |
| 9285 | |
| 9286 | if ( current ) { |
| 9287 | |
| 9288 | // There's only work to do if current dataType is non-auto |
| 9289 | if ( current === "*" ) { |
| 9290 | |
| 9291 | current = prev; |
| 9292 | |
| 9293 | // Convert response if prev dataType is non-auto and differs from current |
| 9294 | } else if ( prev !== "*" && prev !== current ) { |
| 9295 | |
| 9296 | // Seek a direct converter |
| 9297 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
| 9298 | |
| 9299 | // If none found, seek a pair |
| 9300 | if ( !conv ) { |
| 9301 | for ( conv2 in converters ) { |
| 9302 | |
| 9303 | // If conv2 outputs current |
| 9304 | tmp = conv2.split( " " ); |
| 9305 | if ( tmp[ 1 ] === current ) { |
| 9306 | |
| 9307 | // If prev can be converted to accepted input |
| 9308 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
| 9309 | converters[ "* " + tmp[ 0 ] ]; |
| 9310 | if ( conv ) { |
| 9311 | |
| 9312 | // Condense equivalence converters |