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