| 7705 | * Also sets the responseXXX fields on the jqXHR instance |
| 7706 | */ |
| 7707 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
| 7708 | var conv2, current, conv, tmp, prev, |
| 7709 | converters = {}, |
| 7710 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 7711 | dataTypes = s.dataTypes.slice(); |
| 7712 | |
| 7713 | // Create converters map with lowercased keys |
| 7714 | if ( dataTypes[ 1 ] ) { |
| 7715 | for ( conv in s.converters ) { |
| 7716 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
| 7717 | } |
| 7718 | } |
| 7719 | |
| 7720 | current = dataTypes.shift(); |
| 7721 | |
| 7722 | // Convert to each sequential dataType |
| 7723 | while ( current ) { |
| 7724 | |
| 7725 | if ( s.responseFields[ current ] ) { |
| 7726 | jqXHR[ s.responseFields[ current ] ] = response; |
| 7727 | } |
| 7728 | |
| 7729 | // Apply the dataFilter if provided |
| 7730 | if ( !prev && isSuccess && s.dataFilter ) { |
| 7731 | response = s.dataFilter( response, s.dataType ); |
| 7732 | } |
| 7733 | |
| 7734 | prev = current; |
| 7735 | current = dataTypes.shift(); |
| 7736 | |
| 7737 | if ( current ) { |
| 7738 | |
| 7739 | // There's only work to do if current dataType is non-auto |
| 7740 | if ( current === "*" ) { |
| 7741 | |
| 7742 | current = prev; |
| 7743 | |
| 7744 | // Convert response if prev dataType is non-auto and differs from current |
| 7745 | } else if ( prev !== "*" && prev !== current ) { |
| 7746 | |
| 7747 | // Seek a direct converter |
| 7748 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
| 7749 | |
| 7750 | // If none found, seek a pair |
| 7751 | if ( !conv ) { |
| 7752 | for ( conv2 in converters ) { |
| 7753 | |
| 7754 | // If conv2 outputs current |
| 7755 | tmp = conv2.split( " " ); |
| 7756 | if ( tmp[ 1 ] === current ) { |
| 7757 | |
| 7758 | // If prev can be converted to accepted input |
| 7759 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
| 7760 | converters[ "* " + tmp[ 0 ] ]; |
| 7761 | if ( conv ) { |
| 7762 | // Condense equivalence converters |
| 7763 | if ( conv === true ) { |
| 7764 | conv = converters[ conv2 ]; |