| 825 | * - returns the corresponding response |
| 826 | */ |
| 827 | function ajaxHandleResponses( s, jqXHR, responses ) { |
| 828 | |
| 829 | var contents = s.contents, |
| 830 | dataTypes = s.dataTypes, |
| 831 | responseFields = s.responseFields, |
| 832 | ct, |
| 833 | type, |
| 834 | finalDataType, |
| 835 | firstDataType; |
| 836 | |
| 837 | // Fill responseXXX fields |
| 838 | for( type in responseFields ) { |
| 839 | if ( type in responses ) { |
| 840 | jqXHR[ responseFields[type] ] = responses[ type ]; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | // Remove auto dataType and get content-type in the process |
| 845 | while( dataTypes[ 0 ] === "*" ) { |
| 846 | dataTypes.shift(); |
| 847 | if ( ct === undefined ) { |
| 848 | ct = s.mimeType || jqXHR.getResponseHeader( "content-type" ); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | // Check if we're dealing with a known content-type |
| 853 | if ( ct ) { |
| 854 | for ( type in contents ) { |
| 855 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
| 856 | dataTypes.unshift( type ); |
| 857 | break; |
| 858 | } |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | // Check to see if we have a response for the expected dataType |
| 863 | if ( dataTypes[ 0 ] in responses ) { |
| 864 | finalDataType = dataTypes[ 0 ]; |
| 865 | } else { |
| 866 | // Try convertible dataTypes |
| 867 | for ( type in responses ) { |
| 868 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
| 869 | finalDataType = type; |
| 870 | break; |
| 871 | } |
| 872 | if ( !firstDataType ) { |
| 873 | firstDataType = type; |
| 874 | } |
| 875 | } |
| 876 | // Or just use first one |
| 877 | finalDataType = finalDataType || firstDataType; |
| 878 | } |
| 879 | |
| 880 | // If we found a dataType |
| 881 | // We add the dataType to the list if needed |
| 882 | // and return the corresponding response |
| 883 | if ( finalDataType ) { |
| 884 | if ( finalDataType !== dataTypes[ 0 ] ) { |