| @@ 8108-8161 (lines=54) @@ | ||
| 8105 | * - finds the right dataType (mediates between content-type and expected dataType) |
|
| 8106 | * - returns the corresponding response |
|
| 8107 | */ |
|
| 8108 | function ajaxHandleResponses( s, jqXHR, responses ) { |
|
| 8109 | ||
| 8110 | var ct, type, finalDataType, firstDataType, |
|
| 8111 | contents = s.contents, |
|
| 8112 | dataTypes = s.dataTypes; |
|
| 8113 | ||
| 8114 | // Remove auto dataType and get content-type in the process |
|
| 8115 | while ( dataTypes[ 0 ] === "*" ) { |
|
| 8116 | dataTypes.shift(); |
|
| 8117 | if ( ct === undefined ) { |
|
| 8118 | ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" ); |
|
| 8119 | } |
|
| 8120 | } |
|
| 8121 | ||
| 8122 | // Check if we're dealing with a known content-type |
|
| 8123 | if ( ct ) { |
|
| 8124 | for ( type in contents ) { |
|
| 8125 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
|
| 8126 | dataTypes.unshift( type ); |
|
| 8127 | break; |
|
| 8128 | } |
|
| 8129 | } |
|
| 8130 | } |
|
| 8131 | ||
| 8132 | // Check to see if we have a response for the expected dataType |
|
| 8133 | if ( dataTypes[ 0 ] in responses ) { |
|
| 8134 | finalDataType = dataTypes[ 0 ]; |
|
| 8135 | } else { |
|
| 8136 | ||
| 8137 | // Try convertible dataTypes |
|
| 8138 | for ( type in responses ) { |
|
| 8139 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) { |
|
| 8140 | finalDataType = type; |
|
| 8141 | break; |
|
| 8142 | } |
|
| 8143 | if ( !firstDataType ) { |
|
| 8144 | firstDataType = type; |
|
| 8145 | } |
|
| 8146 | } |
|
| 8147 | ||
| 8148 | // Or just use first one |
|
| 8149 | finalDataType = finalDataType || firstDataType; |
|
| 8150 | } |
|
| 8151 | ||
| 8152 | // If we found a dataType |
|
| 8153 | // We add the dataType to the list if needed |
|
| 8154 | // and return the corresponding response |
|
| 8155 | if ( finalDataType ) { |
|
| 8156 | if ( finalDataType !== dataTypes[ 0 ] ) { |
|
| 8157 | dataTypes.unshift( finalDataType ); |
|
| 8158 | } |
|
| 8159 | return responses[ finalDataType ]; |
|
| 8160 | } |
|
| 8161 | } |
|
| 8162 | ||
| 8163 | /* Chain conversions given the request and the original response |
|
| 8164 | * Also sets the responseXXX fields on the jqXHR instance |
|
| @@ 9194-9246 (lines=53) @@ | ||
| 9191 | * - finds the right dataType (mediates between content-type and expected dataType) |
|
| 9192 | * - returns the corresponding response |
|
| 9193 | */ |
|
| 9194 | function ajaxHandleResponses( s, jqXHR, responses ) { |
|
| 9195 | var firstDataType, ct, finalDataType, type, |
|
| 9196 | contents = s.contents, |
|
| 9197 | dataTypes = s.dataTypes; |
|
| 9198 | ||
| 9199 | // Remove auto dataType and get content-type in the process |
|
| 9200 | while ( dataTypes[ 0 ] === "*" ) { |
|
| 9201 | dataTypes.shift(); |
|
| 9202 | if ( ct === undefined ) { |
|
| 9203 | ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" ); |
|
| 9204 | } |
|
| 9205 | } |
|
| 9206 | ||
| 9207 | // Check if we're dealing with a known content-type |
|
| 9208 | if ( ct ) { |
|
| 9209 | for ( type in contents ) { |
|
| 9210 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
|
| 9211 | dataTypes.unshift( type ); |
|
| 9212 | break; |
|
| 9213 | } |
|
| 9214 | } |
|
| 9215 | } |
|
| 9216 | ||
| 9217 | // Check to see if we have a response for the expected dataType |
|
| 9218 | if ( dataTypes[ 0 ] in responses ) { |
|
| 9219 | finalDataType = dataTypes[ 0 ]; |
|
| 9220 | } else { |
|
| 9221 | ||
| 9222 | // Try convertible dataTypes |
|
| 9223 | for ( type in responses ) { |
|
| 9224 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) { |
|
| 9225 | finalDataType = type; |
|
| 9226 | break; |
|
| 9227 | } |
|
| 9228 | if ( !firstDataType ) { |
|
| 9229 | firstDataType = type; |
|
| 9230 | } |
|
| 9231 | } |
|
| 9232 | ||
| 9233 | // Or just use first one |
|
| 9234 | finalDataType = finalDataType || firstDataType; |
|
| 9235 | } |
|
| 9236 | ||
| 9237 | // If we found a dataType |
|
| 9238 | // We add the dataType to the list if needed |
|
| 9239 | // and return the corresponding response |
|
| 9240 | if ( finalDataType ) { |
|
| 9241 | if ( finalDataType !== dataTypes[ 0 ] ) { |
|
| 9242 | dataTypes.unshift( finalDataType ); |
|
| 9243 | } |
|
| 9244 | return responses[ finalDataType ]; |
|
| 9245 | } |
|
| 9246 | } |
|
| 9247 | ||
| 9248 | /* Chain conversions given the request and the original response |
|
| 9249 | * Also sets the responseXXX fields on the jqXHR instance |
|
| @@ 7652-7703 (lines=52) @@ | ||
| 7649 | * - finds the right dataType (mediates between content-type and expected dataType) |
|
| 7650 | * - returns the corresponding response |
|
| 7651 | */ |
|
| 7652 | function ajaxHandleResponses( s, jqXHR, responses ) { |
|
| 7653 | ||
| 7654 | var ct, type, finalDataType, firstDataType, |
|
| 7655 | contents = s.contents, |
|
| 7656 | dataTypes = s.dataTypes; |
|
| 7657 | ||
| 7658 | // Remove auto dataType and get content-type in the process |
|
| 7659 | while ( dataTypes[ 0 ] === "*" ) { |
|
| 7660 | dataTypes.shift(); |
|
| 7661 | if ( ct === undefined ) { |
|
| 7662 | ct = s.mimeType || jqXHR.getResponseHeader("Content-Type"); |
|
| 7663 | } |
|
| 7664 | } |
|
| 7665 | ||
| 7666 | // Check if we're dealing with a known content-type |
|
| 7667 | if ( ct ) { |
|
| 7668 | for ( type in contents ) { |
|
| 7669 | if ( contents[ type ] && contents[ type ].test( ct ) ) { |
|
| 7670 | dataTypes.unshift( type ); |
|
| 7671 | break; |
|
| 7672 | } |
|
| 7673 | } |
|
| 7674 | } |
|
| 7675 | ||
| 7676 | // Check to see if we have a response for the expected dataType |
|
| 7677 | if ( dataTypes[ 0 ] in responses ) { |
|
| 7678 | finalDataType = dataTypes[ 0 ]; |
|
| 7679 | } else { |
|
| 7680 | // Try convertible dataTypes |
|
| 7681 | for ( type in responses ) { |
|
| 7682 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
|
| 7683 | finalDataType = type; |
|
| 7684 | break; |
|
| 7685 | } |
|
| 7686 | if ( !firstDataType ) { |
|
| 7687 | firstDataType = type; |
|
| 7688 | } |
|
| 7689 | } |
|
| 7690 | // Or just use first one |
|
| 7691 | finalDataType = finalDataType || firstDataType; |
|
| 7692 | } |
|
| 7693 | ||
| 7694 | // If we found a dataType |
|
| 7695 | // We add the dataType to the list if needed |
|
| 7696 | // and return the corresponding response |
|
| 7697 | if ( finalDataType ) { |
|
| 7698 | if ( finalDataType !== dataTypes[ 0 ] ) { |
|
| 7699 | dataTypes.unshift( finalDataType ); |
|
| 7700 | } |
|
| 7701 | return responses[ finalDataType ]; |
|
| 7702 | } |
|
| 7703 | } |
|
| 7704 | ||
| 7705 | /* Chain conversions given the request and the original response |
|
| 7706 | * Also sets the responseXXX fields on the jqXHR instance |
|