| 7733 | * - returns the corresponding response |
| 7734 | */ |
| 7735 | function ajaxHandleResponses( s, jqXHR, responses ) { |
| 7736 | |
| 7737 | var contents = s.contents, |
| 7738 | dataTypes = s.dataTypes, |
| 7739 | responseFields = s.responseFields, |
| 7740 | ct, |
| 7741 | type, |
| 7742 | finalDataType, |
| 7743 | firstDataType; |
| 7744 | |
| 7745 | // Fill responseXXX fields |
| 7746 | for ( type in responseFields ) { |
| 7747 | if ( type in responses ) { |
| 7748 | jqXHR[ responseFields[type] ] = responses[ type ]; |
| 7749 | } |
| 7750 | } |
| 7751 | |
| 7752 | // Remove auto dataType and get content-type in the process |
| 7753 | while( dataTypes[ 0 ] === "*" ) { |
| 7754 | dataTypes.shift(); |
| 7755 | if ( ct === undefined ) { |
| 7756 | ct = s.mimeType || jqXHR.getResponseHeader( "content-type" ); |
| 7757 | } |
| 7758 | } |
| 7759 | |
| 7760 | // Check if we're dealing with a known content-type |
| 7761 | if ( ct ) { |
| 7762 | for ( type in contents ) { |
| 7763 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
| 7764 | dataTypes.unshift( type ); |
| 7765 | break; |
| 7766 | } |
| 7767 | } |
| 7768 | } |
| 7769 | |
| 7770 | // Check to see if we have a response for the expected dataType |
| 7771 | if ( dataTypes[ 0 ] in responses ) { |
| 7772 | finalDataType = dataTypes[ 0 ]; |
| 7773 | } else { |
| 7774 | // Try convertible dataTypes |
| 7775 | for ( type in responses ) { |
| 7776 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
| 7777 | finalDataType = type; |
| 7778 | break; |
| 7779 | } |
| 7780 | if ( !firstDataType ) { |
| 7781 | firstDataType = type; |
| 7782 | } |
| 7783 | } |
| 7784 | // Or just use first one |
| 7785 | finalDataType = finalDataType || firstDataType; |
| 7786 | } |
| 7787 | |
| 7788 | // If we found a dataType |
| 7789 | // We add the dataType to the list if needed |
| 7790 | // and return the corresponding response |
| 7791 | if ( finalDataType ) { |
| 7792 | if ( finalDataType !== dataTypes[ 0 ] ) { |