| 7405 | * - returns the corresponding response |
| 7406 | */ |
| 7407 | function ajaxHandleResponses( s, jqXHR, responses ) { |
| 7408 | |
| 7409 | var contents = s.contents, |
| 7410 | dataTypes = s.dataTypes, |
| 7411 | responseFields = s.responseFields, |
| 7412 | ct, |
| 7413 | type, |
| 7414 | finalDataType, |
| 7415 | firstDataType; |
| 7416 | |
| 7417 | // Fill responseXXX fields |
| 7418 | for( type in responseFields ) { |
| 7419 | if ( type in responses ) { |
| 7420 | jqXHR[ responseFields[type] ] = responses[ type ]; |
| 7421 | } |
| 7422 | } |
| 7423 | |
| 7424 | // Remove auto dataType and get content-type in the process |
| 7425 | while( dataTypes[ 0 ] === "*" ) { |
| 7426 | dataTypes.shift(); |
| 7427 | if ( ct === undefined ) { |
| 7428 | ct = s.mimeType || jqXHR.getResponseHeader( "content-type" ); |
| 7429 | } |
| 7430 | } |
| 7431 | |
| 7432 | // Check if we're dealing with a known content-type |
| 7433 | if ( ct ) { |
| 7434 | for ( type in contents ) { |
| 7435 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
| 7436 | dataTypes.unshift( type ); |
| 7437 | break; |
| 7438 | } |
| 7439 | } |
| 7440 | } |
| 7441 | |
| 7442 | // Check to see if we have a response for the expected dataType |
| 7443 | if ( dataTypes[ 0 ] in responses ) { |
| 7444 | finalDataType = dataTypes[ 0 ]; |
| 7445 | } else { |
| 7446 | // Try convertible dataTypes |
| 7447 | for ( type in responses ) { |
| 7448 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
| 7449 | finalDataType = type; |
| 7450 | break; |
| 7451 | } |
| 7452 | if ( !firstDataType ) { |
| 7453 | firstDataType = type; |
| 7454 | } |
| 7455 | } |
| 7456 | // Or just use first one |
| 7457 | finalDataType = finalDataType || firstDataType; |
| 7458 | } |
| 7459 | |
| 7460 | // If we found a dataType |
| 7461 | // We add the dataType to the list if needed |
| 7462 | // and return the corresponding response |
| 7463 | if ( finalDataType ) { |
| 7464 | if ( finalDataType !== dataTypes[ 0 ] ) { |