| 8105 | * Also sets the responseXXX fields on the jqXHR instance |
| 8106 | */ |
| 8107 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
| 8108 | var conv2, current, conv, tmp, prev, |
| 8109 | converters = {}, |
| 8110 | |
| 8111 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 8112 | dataTypes = s.dataTypes.slice(); |
| 8113 | |
| 8114 | // Create converters map with lowercased keys |
| 8115 | if ( dataTypes[ 1 ] ) { |
| 8116 | for ( conv in s.converters ) { |
| 8117 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
| 8118 | } |
| 8119 | } |
| 8120 | |
| 8121 | current = dataTypes.shift(); |
| 8122 | |
| 8123 | // Convert to each sequential dataType |
| 8124 | while ( current ) { |
| 8125 | |
| 8126 | if ( s.responseFields[ current ] ) { |
| 8127 | jqXHR[ s.responseFields[ current ] ] = response; |
| 8128 | } |
| 8129 | |
| 8130 | // Apply the dataFilter if provided |
| 8131 | if ( !prev && isSuccess && s.dataFilter ) { |
| 8132 | response = s.dataFilter( response, s.dataType ); |
| 8133 | } |
| 8134 | |
| 8135 | prev = current; |
| 8136 | current = dataTypes.shift(); |
| 8137 | |
| 8138 | if ( current ) { |
| 8139 | |
| 8140 | // There's only work to do if current dataType is non-auto |
| 8141 | if ( current === "*" ) { |
| 8142 | |
| 8143 | current = prev; |
| 8144 | |
| 8145 | // Convert response if prev dataType is non-auto and differs from current |
| 8146 | } else if ( prev !== "*" && prev !== current ) { |
| 8147 | |
| 8148 | // Seek a direct converter |
| 8149 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
| 8150 | |
| 8151 | // If none found, seek a pair |
| 8152 | if ( !conv ) { |
| 8153 | for ( conv2 in converters ) { |
| 8154 | |
| 8155 | // If conv2 outputs current |
| 8156 | tmp = conv2.split( " " ); |
| 8157 | if ( tmp[ 1 ] === current ) { |
| 8158 | |
| 8159 | // If prev can be converted to accepted input |
| 8160 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
| 8161 | converters[ "* " + tmp[ 0 ] ]; |
| 8162 | if ( conv ) { |
| 8163 | |
| 8164 | // Condense equivalence converters |