+ // This will be ignored by ajaxPrefilter
+ // so it's safe to return no matter what
+ return selected;
+ }
+}
+
+function addToPrefiltersOrTransports( structure, dataTypeExpression, functor ) {
+
+ var dataTypes = dataTypeExpression.split( rspacesAjax ),
+ i = 0,
+ length = dataTypes.length,
+ dataType,
+ list,
+ placeBefore;
+
+ // For each dataType in the dataTypeExpression
+ for(; i < length; i++ ) {
+ dataType = dataTypes[ i ];
+ // We control if we're asked to add before
+ // any existing element
+ placeBefore = /^\+/.test( dataType );
+ if ( placeBefore ) {
+ dataType = dataType.substr( 1 );
+ }
+ list = structure[ dataType ] = structure[ dataType ] || [];
+ // then we add to the structure accordingly
+ list[ placeBefore ? "unshift" : "push" ]( functor );
+ }
+}
+
+// Base function for both ajaxPrefilter and ajaxTransport
+function prefiltersOrTransports( structure, arg1, arg2, type /* internal */ ) {
+
+ type = jQuery.type( arg1 );
+
+ if ( type === "object" ) {
+ // We have an options map so we have to inspect the structure
+ return inspectPrefiltersOrTransports( structure, arg1, arg2 );
+ } else {
+ // We're requested to add to the structure
+ // Signature is ( dataTypeExpression, function )
+ // with dataTypeExpression being optional and
+ // defaulting to auto ("*")
+ type = ( type === "function" );
+ if ( type ) {
+ arg2 = arg1;
+ arg1 = undefined;
+ }
+ // We control that the second argument is really a function
+ if ( type || jQuery.isFunction( arg2 ) ) {
+ addToPrefiltersOrTransports( structure, arg1 || "*", arg2 );
+ }
+ }
+}
+
+/* Handles responses to an ajax request:
+ * - sets all responseXXX fields accordingly
+ * - finds the right dataType (mediates between content-type and expected dataType)
+ * - returns the corresponding response
+ */
+function ajaxHandleResponses( s, jXHR, responses ) {
+
+ var contents = s.contents,
+ dataTypes = s.dataTypes,
+ responseFields = s.responseFields,
+ ct,
+ type,
+ finalDataType,
+ firstDataType;
+
+ // Fill responseXXX fields
+ for( type in responseFields ) {
+ if ( type in responses ) {
+ jXHR[ responseFields[type] ] = responses[ type ];
+ }
+ }