| 7817 | * - returns the corresponding response |
| 7818 | */ |
| 7819 | function ajaxHandleResponses( s, jqXHR, responses ) { |
| 7820 | |
| 7821 | var contents = s.contents, |
| 7822 | dataTypes = s.dataTypes, |
| 7823 | responseFields = s.responseFields, |
| 7824 | ct, |
| 7825 | type, |
| 7826 | finalDataType, |
| 7827 | firstDataType; |
| 7828 | |
| 7829 | // Fill responseXXX fields |
| 7830 | for ( type in responseFields ) { |
| 7831 | if ( type in responses ) { |
| 7832 | jqXHR[ responseFields[type] ] = responses[ type ]; |
| 7833 | } |
| 7834 | } |
| 7835 | |
| 7836 | // Remove auto dataType and get content-type in the process |
| 7837 | while( dataTypes[ 0 ] === "*" ) { |
| 7838 | dataTypes.shift(); |
| 7839 | if ( ct === undefined ) { |
| 7840 | ct = s.mimeType || jqXHR.getResponseHeader( "content-type" ); |
| 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | // Check if we're dealing with a known content-type |
| 7845 | if ( ct ) { |
| 7846 | for ( type in contents ) { |
| 7847 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
| 7848 | dataTypes.unshift( type ); |
| 7849 | break; |
| 7850 | } |
| 7851 | } |
| 7852 | } |
| 7853 | |
| 7854 | // Check to see if we have a response for the expected dataType |
| 7855 | if ( dataTypes[ 0 ] in responses ) { |
| 7856 | finalDataType = dataTypes[ 0 ]; |
| 7857 | } else { |
| 7858 | // Try convertible dataTypes |
| 7859 | for ( type in responses ) { |
| 7860 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
| 7861 | finalDataType = type; |
| 7862 | break; |
| 7863 | } |
| 7864 | if ( !firstDataType ) { |
| 7865 | firstDataType = type; |
| 7866 | } |
| 7867 | } |
| 7868 | // Or just use first one |
| 7869 | finalDataType = finalDataType || firstDataType; |
| 7870 | } |
| 7871 | |
| 7872 | // If we found a dataType |
| 7873 | // We add the dataType to the list if needed |
| 7874 | // and return the corresponding response |
| 7875 | if ( finalDataType ) { |
| 7876 | if ( finalDataType !== dataTypes[ 0 ] ) { |