| 5117 | * Also sets the responseXXX fields on the jqXHR instance |
| 5118 | */ |
| 5119 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
| 5120 | var conv2, current, conv, tmp, prev, |
| 5121 | converters = {}, |
| 5122 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 5123 | dataTypes = s.dataTypes.slice(); |
| 5124 | |
| 5125 | // Create converters map with lowercased keys |
| 5126 | if ( dataTypes[ 1 ] ) { |
| 5127 | for ( conv in s.converters ) { |
| 5128 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
| 5129 | } |
| 5130 | } |
| 5131 | |
| 5132 | current = dataTypes.shift(); |
| 5133 | |
| 5134 | // Convert to each sequential dataType |
| 5135 | while ( current ) { |
| 5136 | |
| 5137 | if ( s.responseFields[ current ] ) { |
| 5138 | jqXHR[ s.responseFields[ current ] ] = response; |
| 5139 | } |
| 5140 | |
| 5141 | // Apply the dataFilter if provided |
| 5142 | if ( !prev && isSuccess && s.dataFilter ) { |
| 5143 | response = s.dataFilter( response, s.dataType ); |
| 5144 | } |
| 5145 | |
| 5146 | prev = current; |
| 5147 | current = dataTypes.shift(); |
| 5148 | |
| 5149 | if ( current ) { |
| 5150 | |
| 5151 | // There's only work to do if current dataType is non-auto |
| 5152 | if ( current === "*" ) { |
| 5153 | |
| 5154 | current = prev; |
| 5155 | |
| 5156 | // Convert response if prev dataType is non-auto and differs from current |
| 5157 | } else if ( prev !== "*" && prev !== current ) { |
| 5158 | |
| 5159 | // Seek a direct converter |
| 5160 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
| 5161 | |
| 5162 | // If none found, seek a pair |
| 5163 | if ( !conv ) { |
| 5164 | for ( conv2 in converters ) { |
| 5165 | |
| 5166 | // If conv2 outputs current |
| 5167 | tmp = conv2.split( " " ); |
| 5168 | if ( tmp[ 1 ] === current ) { |
| 5169 | |
| 5170 | // If prev can be converted to accepted input |
| 5171 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
| 5172 | converters[ "* " + tmp[ 0 ] ]; |
| 5173 | if ( conv ) { |
| 5174 | // Condense equivalence converters |
| 5175 | if ( conv === true ) { |
| 5176 | conv = converters[ conv2 ]; |