| 196 | * Also sets the responseXXX fields on the jqXHR instance |
| 197 | */ |
| 198 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
| 199 | var conv2, current, conv, tmp, prev, |
| 200 | converters = {}, |
| 201 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 202 | dataTypes = s.dataTypes.slice(); |
| 203 | |
| 204 | // Create converters map with lowercased keys |
| 205 | if ( dataTypes[ 1 ] ) { |
| 206 | for ( conv in s.converters ) { |
| 207 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | current = dataTypes.shift(); |
| 212 | |
| 213 | // Convert to each sequential dataType |
| 214 | while ( current ) { |
| 215 | |
| 216 | if ( s.responseFields[ current ] ) { |
| 217 | jqXHR[ s.responseFields[ current ] ] = response; |
| 218 | } |
| 219 | |
| 220 | // Apply the dataFilter if provided |
| 221 | if ( !prev && isSuccess && s.dataFilter ) { |
| 222 | response = s.dataFilter( response, s.dataType ); |
| 223 | } |
| 224 | |
| 225 | prev = current; |
| 226 | current = dataTypes.shift(); |
| 227 | |
| 228 | if ( current ) { |
| 229 | |
| 230 | // There's only work to do if current dataType is non-auto |
| 231 | if ( current === "*" ) { |
| 232 | |
| 233 | current = prev; |
| 234 | |
| 235 | // Convert response if prev dataType is non-auto and differs from current |
| 236 | } else if ( prev !== "*" && prev !== current ) { |
| 237 | |
| 238 | // Seek a direct converter |
| 239 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
| 240 | |
| 241 | // If none found, seek a pair |
| 242 | if ( !conv ) { |
| 243 | for ( conv2 in converters ) { |
| 244 | |
| 245 | // If conv2 outputs current |
| 246 | tmp = conv2.split( " " ); |
| 247 | if ( tmp[ 1 ] === current ) { |
| 248 | |
| 249 | // If prev can be converted to accepted input |
| 250 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
| 251 | converters[ "* " + tmp[ 0 ] ]; |
| 252 | if ( conv ) { |
| 253 | // Condense equivalence converters |
| 254 | if ( conv === true ) { |
| 255 | conv = converters[ conv2 ]; |