MCPcopy Create free account
hub / github.com/sql-js/sql.js / ajaxHandleResponses

Function ajaxHandleResponses

documentation/javascript/application.js:8762–8821  ·  view source on GitHub ↗
( s, jqXHR, responses )

Source from the content-addressed store, hash-verified

8760 * - returns the corresponding response
8761 */
8762function ajaxHandleResponses( s, jqXHR, responses ) {
8763
8764 var ct, type, finalDataType, firstDataType,
8765 contents = s.contents,
8766 dataTypes = s.dataTypes,
8767 responseFields = s.responseFields;
8768
8769 // Fill responseXXX fields
8770 for ( type in responseFields ) {
8771 if ( type in responses ) {
8772 jqXHR[ responseFields[type] ] = responses[ type ];
8773 }
8774 }
8775
8776 // Remove auto dataType and get content-type in the process
8777 while( dataTypes[ 0 ] === "*" ) {
8778 dataTypes.shift();
8779 if ( ct === undefined ) {
8780 ct = s.mimeType || jqXHR.getResponseHeader( "content-type" );
8781 }
8782 }
8783
8784 // Check if we're dealing with a known content-type
8785 if ( ct ) {
8786 for ( type in contents ) {
8787 if ( contents[ type ] && contents[ type ].test( ct ) ) {
8788 dataTypes.unshift( type );
8789 break;
8790 }
8791 }
8792 }
8793
8794 // Check to see if we have a response for the expected dataType
8795 if ( dataTypes[ 0 ] in responses ) {
8796 finalDataType = dataTypes[ 0 ];
8797 } else {
8798 // Try convertible dataTypes
8799 for ( type in responses ) {
8800 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
8801 finalDataType = type;
8802 break;
8803 }
8804 if ( !firstDataType ) {
8805 firstDataType = type;
8806 }
8807 }
8808 // Or just use first one
8809 finalDataType = finalDataType || firstDataType;
8810 }
8811
8812 // If we found a dataType
8813 // We add the dataType to the list if needed
8814 // and return the corresponding response
8815 if ( finalDataType ) {
8816 if ( finalDataType !== dataTypes[ 0 ] ) {
8817 dataTypes.unshift( finalDataType );
8818 }
8819 return responses[ finalDataType ];

Callers 1

doneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…