| 9178 | * Also sets the responseXXX fields on the jqXHR instance |
| 9179 | */ |
| 9180 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
| 9181 | var conv2, current, conv, tmp, prev, |
| 9182 | converters = {}, |
| 9183 | |
| 9184 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 9185 | dataTypes = s.dataTypes.slice(); |
| 9186 | |
| 9187 | // Create converters map with lowercased keys |
| 9188 | if ( dataTypes[ 1 ] ) { |
| 9189 | for ( conv in s.converters ) { |
| 9190 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
| 9191 | } |
| 9192 | } |
| 9193 | |
| 9194 | current = dataTypes.shift(); |
| 9195 | |
| 9196 | // Convert to each sequential dataType |
| 9197 | while ( current ) { |
| 9198 | |
| 9199 | if ( s.responseFields[ current ] ) { |
| 9200 | jqXHR[ s.responseFields[ current ] ] = response; |
| 9201 | } |
| 9202 | |
| 9203 | // Apply the dataFilter if provided |
| 9204 | if ( !prev && isSuccess && s.dataFilter ) { |
| 9205 | response = s.dataFilter( response, s.dataType ); |
| 9206 | } |
| 9207 | |
| 9208 | prev = current; |
| 9209 | current = dataTypes.shift(); |
| 9210 | |
| 9211 | if ( current ) { |
| 9212 | |
| 9213 | // There's only work to do if current dataType is non-auto |
| 9214 | if ( current === "*" ) { |
| 9215 | |
| 9216 | current = prev; |
| 9217 | |
| 9218 | // Convert response if prev dataType is non-auto and differs from current |
| 9219 | } else if ( prev !== "*" && prev !== current ) { |
| 9220 | |
| 9221 | // Seek a direct converter |
| 9222 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
| 9223 | |
| 9224 | // If none found, seek a pair |
| 9225 | if ( !conv ) { |
| 9226 | for ( conv2 in converters ) { |
| 9227 | |
| 9228 | // If conv2 outputs current |
| 9229 | tmp = conv2.split( " " ); |
| 9230 | if ( tmp[ 1 ] === current ) { |
| 9231 | |
| 9232 | // If prev can be converted to accepted input |
| 9233 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
| 9234 | converters[ "* " + tmp[ 0 ] ]; |
| 9235 | if ( conv ) { |
| 9236 | |
| 9237 | // Condense equivalence converters |