| 7639 | * Also sets the responseXXX fields on the jqXHR instance |
| 7640 | */ |
| 7641 | function ajaxConvert( s, response, jqXHR, isSuccess ) { |
| 7642 | var conv2, current, conv, tmp, prev, |
| 7643 | converters = {}, |
| 7644 | // Work with a copy of dataTypes in case we need to modify it for conversion |
| 7645 | dataTypes = s.dataTypes.slice(); |
| 7646 | |
| 7647 | // Create converters map with lowercased keys |
| 7648 | if ( dataTypes[ 1 ] ) { |
| 7649 | for ( conv in s.converters ) { |
| 7650 | converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
| 7651 | } |
| 7652 | } |
| 7653 | |
| 7654 | current = dataTypes.shift(); |
| 7655 | |
| 7656 | // Convert to each sequential dataType |
| 7657 | while ( current ) { |
| 7658 | |
| 7659 | if ( s.responseFields[ current ] ) { |
| 7660 | jqXHR[ s.responseFields[ current ] ] = response; |
| 7661 | } |
| 7662 | |
| 7663 | // Apply the dataFilter if provided |
| 7664 | if ( !prev && isSuccess && s.dataFilter ) { |
| 7665 | response = s.dataFilter( response, s.dataType ); |
| 7666 | } |
| 7667 | |
| 7668 | prev = current; |
| 7669 | current = dataTypes.shift(); |
| 7670 | |
| 7671 | if ( current ) { |
| 7672 | |
| 7673 | // There's only work to do if current dataType is non-auto |
| 7674 | if ( current === "*" ) { |
| 7675 | |
| 7676 | current = prev; |
| 7677 | |
| 7678 | // Convert response if prev dataType is non-auto and differs from current |
| 7679 | } else if ( prev !== "*" && prev !== current ) { |
| 7680 | |
| 7681 | // Seek a direct converter |
| 7682 | conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
| 7683 | |
| 7684 | // If none found, seek a pair |
| 7685 | if ( !conv ) { |
| 7686 | for ( conv2 in converters ) { |
| 7687 | |
| 7688 | // If conv2 outputs current |
| 7689 | tmp = conv2.split( " " ); |
| 7690 | if ( tmp[ 1 ] === current ) { |
| 7691 | |
| 7692 | // If prev can be converted to accepted input |
| 7693 | conv = converters[ prev + " " + tmp[ 0 ] ] || |
| 7694 | converters[ "* " + tmp[ 0 ] ]; |
| 7695 | if ( conv ) { |
| 7696 | // Condense equivalence converters |
| 7697 | if ( conv === true ) { |
| 7698 | conv = converters[ conv2 ]; |