UPDATE 4.4.0.0
[phpmyadmin.git] / js / jquery / src / jquery / ajax.js
blob1b01fd6a5474dcd7717697dbe0290338d712d000
1 define([
2         "./core",
3         "./var/rnotwhite",
4         "./ajax/var/nonce",
5         "./ajax/var/rquery",
6         "./core/init",
7         "./ajax/parseJSON",
8         "./ajax/parseXML",
9         "./deferred"
10 ], function( jQuery, rnotwhite, nonce, rquery ) {
12 var
13         // Document location
14         ajaxLocParts,
15         ajaxLocation,
17         rhash = /#.*$/,
18         rts = /([?&])_=[^&]*/,
19         rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
20         // #7653, #8125, #8152: local protocol detection
21         rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
22         rnoContent = /^(?:GET|HEAD)$/,
23         rprotocol = /^\/\//,
24         rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
26         /* Prefilters
27          * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
28          * 2) These are called:
29          *    - BEFORE asking for a transport
30          *    - AFTER param serialization (s.data is a string if s.processData is true)
31          * 3) key is the dataType
32          * 4) the catchall symbol "*" can be used
33          * 5) execution will start with transport dataType and THEN continue down to "*" if needed
34          */
35         prefilters = {},
37         /* Transports bindings
38          * 1) key is the dataType
39          * 2) the catchall symbol "*" can be used
40          * 3) selection will start with transport dataType and THEN go to "*" if needed
41          */
42         transports = {},
44         // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
45         allTypes = "*/".concat("*");
47 // #8138, IE may throw an exception when accessing
48 // a field from window.location if document.domain has been set
49 try {
50         ajaxLocation = location.href;
51 } catch( e ) {
52         // Use the href attribute of an A element
53         // since IE will modify it given document.location
54         ajaxLocation = document.createElement( "a" );
55         ajaxLocation.href = "";
56         ajaxLocation = ajaxLocation.href;
59 // Segment location into parts
60 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
62 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
63 function addToPrefiltersOrTransports( structure ) {
65         // dataTypeExpression is optional and defaults to "*"
66         return function( dataTypeExpression, func ) {
68                 if ( typeof dataTypeExpression !== "string" ) {
69                         func = dataTypeExpression;
70                         dataTypeExpression = "*";
71                 }
73                 var dataType,
74                         i = 0,
75                         dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
77                 if ( jQuery.isFunction( func ) ) {
78                         // For each dataType in the dataTypeExpression
79                         while ( (dataType = dataTypes[i++]) ) {
80                                 // Prepend if requested
81                                 if ( dataType.charAt( 0 ) === "+" ) {
82                                         dataType = dataType.slice( 1 ) || "*";
83                                         (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
85                                 // Otherwise append
86                                 } else {
87                                         (structure[ dataType ] = structure[ dataType ] || []).push( func );
88                                 }
89                         }
90                 }
91         };
94 // Base inspection function for prefilters and transports
95 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
97         var inspected = {},
98                 seekingTransport = ( structure === transports );
100         function inspect( dataType ) {
101                 var selected;
102                 inspected[ dataType ] = true;
103                 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
104                         var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
105                         if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
106                                 options.dataTypes.unshift( dataTypeOrTransport );
107                                 inspect( dataTypeOrTransport );
108                                 return false;
109                         } else if ( seekingTransport ) {
110                                 return !( selected = dataTypeOrTransport );
111                         }
112                 });
113                 return selected;
114         }
116         return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
119 // A special extend for ajax options
120 // that takes "flat" options (not to be deep extended)
121 // Fixes #9887
122 function ajaxExtend( target, src ) {
123         var deep, key,
124                 flatOptions = jQuery.ajaxSettings.flatOptions || {};
126         for ( key in src ) {
127                 if ( src[ key ] !== undefined ) {
128                         ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
129                 }
130         }
131         if ( deep ) {
132                 jQuery.extend( true, target, deep );
133         }
135         return target;
138 /* Handles responses to an ajax request:
139  * - finds the right dataType (mediates between content-type and expected dataType)
140  * - returns the corresponding response
141  */
142 function ajaxHandleResponses( s, jqXHR, responses ) {
143         var firstDataType, ct, finalDataType, type,
144                 contents = s.contents,
145                 dataTypes = s.dataTypes;
147         // Remove auto dataType and get content-type in the process
148         while ( dataTypes[ 0 ] === "*" ) {
149                 dataTypes.shift();
150                 if ( ct === undefined ) {
151                         ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
152                 }
153         }
155         // Check if we're dealing with a known content-type
156         if ( ct ) {
157                 for ( type in contents ) {
158                         if ( contents[ type ] && contents[ type ].test( ct ) ) {
159                                 dataTypes.unshift( type );
160                                 break;
161                         }
162                 }
163         }
165         // Check to see if we have a response for the expected dataType
166         if ( dataTypes[ 0 ] in responses ) {
167                 finalDataType = dataTypes[ 0 ];
168         } else {
169                 // Try convertible dataTypes
170                 for ( type in responses ) {
171                         if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
172                                 finalDataType = type;
173                                 break;
174                         }
175                         if ( !firstDataType ) {
176                                 firstDataType = type;
177                         }
178                 }
179                 // Or just use first one
180                 finalDataType = finalDataType || firstDataType;
181         }
183         // If we found a dataType
184         // We add the dataType to the list if needed
185         // and return the corresponding response
186         if ( finalDataType ) {
187                 if ( finalDataType !== dataTypes[ 0 ] ) {
188                         dataTypes.unshift( finalDataType );
189                 }
190                 return responses[ finalDataType ];
191         }
194 /* Chain conversions given the request and the original response
195  * Also sets the responseXXX fields on the jqXHR instance
196  */
197 function ajaxConvert( s, response, jqXHR, isSuccess ) {
198         var conv2, current, conv, tmp, prev,
199                 converters = {},
200                 // Work with a copy of dataTypes in case we need to modify it for conversion
201                 dataTypes = s.dataTypes.slice();
203         // Create converters map with lowercased keys
204         if ( dataTypes[ 1 ] ) {
205                 for ( conv in s.converters ) {
206                         converters[ conv.toLowerCase() ] = s.converters[ conv ];
207                 }
208         }
210         current = dataTypes.shift();
212         // Convert to each sequential dataType
213         while ( current ) {
215                 if ( s.responseFields[ current ] ) {
216                         jqXHR[ s.responseFields[ current ] ] = response;
217                 }
219                 // Apply the dataFilter if provided
220                 if ( !prev && isSuccess && s.dataFilter ) {
221                         response = s.dataFilter( response, s.dataType );
222                 }
224                 prev = current;
225                 current = dataTypes.shift();
227                 if ( current ) {
229                         // There's only work to do if current dataType is non-auto
230                         if ( current === "*" ) {
232                                 current = prev;
234                         // Convert response if prev dataType is non-auto and differs from current
235                         } else if ( prev !== "*" && prev !== current ) {
237                                 // Seek a direct converter
238                                 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
240                                 // If none found, seek a pair
241                                 if ( !conv ) {
242                                         for ( conv2 in converters ) {
244                                                 // If conv2 outputs current
245                                                 tmp = conv2.split( " " );
246                                                 if ( tmp[ 1 ] === current ) {
248                                                         // If prev can be converted to accepted input
249                                                         conv = converters[ prev + " " + tmp[ 0 ] ] ||
250                                                                 converters[ "* " + tmp[ 0 ] ];
251                                                         if ( conv ) {
252                                                                 // Condense equivalence converters
253                                                                 if ( conv === true ) {
254                                                                         conv = converters[ conv2 ];
256                                                                 // Otherwise, insert the intermediate dataType
257                                                                 } else if ( converters[ conv2 ] !== true ) {
258                                                                         current = tmp[ 0 ];
259                                                                         dataTypes.unshift( tmp[ 1 ] );
260                                                                 }
261                                                                 break;
262                                                         }
263                                                 }
264                                         }
265                                 }
267                                 // Apply converter (if not an equivalence)
268                                 if ( conv !== true ) {
270                                         // Unless errors are allowed to bubble, catch and return them
271                                         if ( conv && s[ "throws" ] ) {
272                                                 response = conv( response );
273                                         } else {
274                                                 try {
275                                                         response = conv( response );
276                                                 } catch ( e ) {
277                                                         return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
278                                                 }
279                                         }
280                                 }
281                         }
282                 }
283         }
285         return { state: "success", data: response };
288 jQuery.extend({
290         // Counter for holding the number of active queries
291         active: 0,
293         // Last-Modified header cache for next request
294         lastModified: {},
295         etag: {},
297         ajaxSettings: {
298                 url: ajaxLocation,
299                 type: "GET",
300                 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
301                 global: true,
302                 processData: true,
303                 async: true,
304                 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
305                 /*
306                 timeout: 0,
307                 data: null,
308                 dataType: null,
309                 username: null,
310                 password: null,
311                 cache: null,
312                 throws: false,
313                 traditional: false,
314                 headers: {},
315                 */
317                 accepts: {
318                         "*": allTypes,
319                         text: "text/plain",
320                         html: "text/html",
321                         xml: "application/xml, text/xml",
322                         json: "application/json, text/javascript"
323                 },
325                 contents: {
326                         xml: /xml/,
327                         html: /html/,
328                         json: /json/
329                 },
331                 responseFields: {
332                         xml: "responseXML",
333                         text: "responseText",
334                         json: "responseJSON"
335                 },
337                 // Data converters
338                 // Keys separate source (or catchall "*") and destination types with a single space
339                 converters: {
341                         // Convert anything to text
342                         "* text": String,
344                         // Text to html (true = no transformation)
345                         "text html": true,
347                         // Evaluate text as a json expression
348                         "text json": jQuery.parseJSON,
350                         // Parse text as xml
351                         "text xml": jQuery.parseXML
352                 },
354                 // For options that shouldn't be deep extended:
355                 // you can add your own custom options here if
356                 // and when you create one that shouldn't be
357                 // deep extended (see ajaxExtend)
358                 flatOptions: {
359                         url: true,
360                         context: true
361                 }
362         },
364         // Creates a full fledged settings object into target
365         // with both ajaxSettings and settings fields.
366         // If target is omitted, writes into ajaxSettings.
367         ajaxSetup: function( target, settings ) {
368                 return settings ?
370                         // Building a settings object
371                         ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
373                         // Extending ajaxSettings
374                         ajaxExtend( jQuery.ajaxSettings, target );
375         },
377         ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
378         ajaxTransport: addToPrefiltersOrTransports( transports ),
380         // Main method
381         ajax: function( url, options ) {
383                 // If url is an object, simulate pre-1.5 signature
384                 if ( typeof url === "object" ) {
385                         options = url;
386                         url = undefined;
387                 }
389                 // Force options to be an object
390                 options = options || {};
392                 var // Cross-domain detection vars
393                         parts,
394                         // Loop variable
395                         i,
396                         // URL without anti-cache param
397                         cacheURL,
398                         // Response headers as string
399                         responseHeadersString,
400                         // timeout handle
401                         timeoutTimer,
403                         // To know if global events are to be dispatched
404                         fireGlobals,
406                         transport,
407                         // Response headers
408                         responseHeaders,
409                         // Create the final options object
410                         s = jQuery.ajaxSetup( {}, options ),
411                         // Callbacks context
412                         callbackContext = s.context || s,
413                         // Context for global events is callbackContext if it is a DOM node or jQuery collection
414                         globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
415                                 jQuery( callbackContext ) :
416                                 jQuery.event,
417                         // Deferreds
418                         deferred = jQuery.Deferred(),
419                         completeDeferred = jQuery.Callbacks("once memory"),
420                         // Status-dependent callbacks
421                         statusCode = s.statusCode || {},
422                         // Headers (they are sent all at once)
423                         requestHeaders = {},
424                         requestHeadersNames = {},
425                         // The jqXHR state
426                         state = 0,
427                         // Default abort message
428                         strAbort = "canceled",
429                         // Fake xhr
430                         jqXHR = {
431                                 readyState: 0,
433                                 // Builds headers hashtable if needed
434                                 getResponseHeader: function( key ) {
435                                         var match;
436                                         if ( state === 2 ) {
437                                                 if ( !responseHeaders ) {
438                                                         responseHeaders = {};
439                                                         while ( (match = rheaders.exec( responseHeadersString )) ) {
440                                                                 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
441                                                         }
442                                                 }
443                                                 match = responseHeaders[ key.toLowerCase() ];
444                                         }
445                                         return match == null ? null : match;
446                                 },
448                                 // Raw string
449                                 getAllResponseHeaders: function() {
450                                         return state === 2 ? responseHeadersString : null;
451                                 },
453                                 // Caches the header
454                                 setRequestHeader: function( name, value ) {
455                                         var lname = name.toLowerCase();
456                                         if ( !state ) {
457                                                 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
458                                                 requestHeaders[ name ] = value;
459                                         }
460                                         return this;
461                                 },
463                                 // Overrides response content-type header
464                                 overrideMimeType: function( type ) {
465                                         if ( !state ) {
466                                                 s.mimeType = type;
467                                         }
468                                         return this;
469                                 },
471                                 // Status-dependent callbacks
472                                 statusCode: function( map ) {
473                                         var code;
474                                         if ( map ) {
475                                                 if ( state < 2 ) {
476                                                         for ( code in map ) {
477                                                                 // Lazy-add the new callback in a way that preserves old ones
478                                                                 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
479                                                         }
480                                                 } else {
481                                                         // Execute the appropriate callbacks
482                                                         jqXHR.always( map[ jqXHR.status ] );
483                                                 }
484                                         }
485                                         return this;
486                                 },
488                                 // Cancel the request
489                                 abort: function( statusText ) {
490                                         var finalText = statusText || strAbort;
491                                         if ( transport ) {
492                                                 transport.abort( finalText );
493                                         }
494                                         done( 0, finalText );
495                                         return this;
496                                 }
497                         };
499                 // Attach deferreds
500                 deferred.promise( jqXHR ).complete = completeDeferred.add;
501                 jqXHR.success = jqXHR.done;
502                 jqXHR.error = jqXHR.fail;
504                 // Remove hash character (#7531: and string promotion)
505                 // Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
506                 // Handle falsy url in the settings object (#10093: consistency with old signature)
507                 // We also use the url parameter if available
508                 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
510                 // Alias method option to type as per ticket #12004
511                 s.type = options.method || options.type || s.method || s.type;
513                 // Extract dataTypes list
514                 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
516                 // A cross-domain request is in order when we have a protocol:host:port mismatch
517                 if ( s.crossDomain == null ) {
518                         parts = rurl.exec( s.url.toLowerCase() );
519                         s.crossDomain = !!( parts &&
520                                 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
521                                         ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
522                                                 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
523                         );
524                 }
526                 // Convert data if not already a string
527                 if ( s.data && s.processData && typeof s.data !== "string" ) {
528                         s.data = jQuery.param( s.data, s.traditional );
529                 }
531                 // Apply prefilters
532                 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
534                 // If request was aborted inside a prefilter, stop there
535                 if ( state === 2 ) {
536                         return jqXHR;
537                 }
539                 // We can fire global events as of now if asked to
540                 fireGlobals = s.global;
542                 // Watch for a new set of requests
543                 if ( fireGlobals && jQuery.active++ === 0 ) {
544                         jQuery.event.trigger("ajaxStart");
545                 }
547                 // Uppercase the type
548                 s.type = s.type.toUpperCase();
550                 // Determine if request has content
551                 s.hasContent = !rnoContent.test( s.type );
553                 // Save the URL in case we're toying with the If-Modified-Since
554                 // and/or If-None-Match header later on
555                 cacheURL = s.url;
557                 // More options handling for requests with no content
558                 if ( !s.hasContent ) {
560                         // If data is available, append data to url
561                         if ( s.data ) {
562                                 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
563                                 // #9682: remove data so that it's not used in an eventual retry
564                                 delete s.data;
565                         }
567                         // Add anti-cache in url if needed
568                         if ( s.cache === false ) {
569                                 s.url = rts.test( cacheURL ) ?
571                                         // If there is already a '_' parameter, set its value
572                                         cacheURL.replace( rts, "$1_=" + nonce++ ) :
574                                         // Otherwise add one to the end
575                                         cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
576                         }
577                 }
579                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
580                 if ( s.ifModified ) {
581                         if ( jQuery.lastModified[ cacheURL ] ) {
582                                 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
583                         }
584                         if ( jQuery.etag[ cacheURL ] ) {
585                                 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
586                         }
587                 }
589                 // Set the correct header, if data is being sent
590                 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
591                         jqXHR.setRequestHeader( "Content-Type", s.contentType );
592                 }
594                 // Set the Accepts header for the server, depending on the dataType
595                 jqXHR.setRequestHeader(
596                         "Accept",
597                         s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
598                                 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
599                                 s.accepts[ "*" ]
600                 );
602                 // Check for headers option
603                 for ( i in s.headers ) {
604                         jqXHR.setRequestHeader( i, s.headers[ i ] );
605                 }
607                 // Allow custom headers/mimetypes and early abort
608                 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
609                         // Abort if not done already and return
610                         return jqXHR.abort();
611                 }
613                 // aborting is no longer a cancellation
614                 strAbort = "abort";
616                 // Install callbacks on deferreds
617                 for ( i in { success: 1, error: 1, complete: 1 } ) {
618                         jqXHR[ i ]( s[ i ] );
619                 }
621                 // Get transport
622                 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
624                 // If no transport, we auto-abort
625                 if ( !transport ) {
626                         done( -1, "No Transport" );
627                 } else {
628                         jqXHR.readyState = 1;
630                         // Send global event
631                         if ( fireGlobals ) {
632                                 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
633                         }
634                         // Timeout
635                         if ( s.async && s.timeout > 0 ) {
636                                 timeoutTimer = setTimeout(function() {
637                                         jqXHR.abort("timeout");
638                                 }, s.timeout );
639                         }
641                         try {
642                                 state = 1;
643                                 transport.send( requestHeaders, done );
644                         } catch ( e ) {
645                                 // Propagate exception as error if not done
646                                 if ( state < 2 ) {
647                                         done( -1, e );
648                                 // Simply rethrow otherwise
649                                 } else {
650                                         throw e;
651                                 }
652                         }
653                 }
655                 // Callback for when everything is done
656                 function done( status, nativeStatusText, responses, headers ) {
657                         var isSuccess, success, error, response, modified,
658                                 statusText = nativeStatusText;
660                         // Called once
661                         if ( state === 2 ) {
662                                 return;
663                         }
665                         // State is "done" now
666                         state = 2;
668                         // Clear timeout if it exists
669                         if ( timeoutTimer ) {
670                                 clearTimeout( timeoutTimer );
671                         }
673                         // Dereference transport for early garbage collection
674                         // (no matter how long the jqXHR object will be used)
675                         transport = undefined;
677                         // Cache response headers
678                         responseHeadersString = headers || "";
680                         // Set readyState
681                         jqXHR.readyState = status > 0 ? 4 : 0;
683                         // Determine if successful
684                         isSuccess = status >= 200 && status < 300 || status === 304;
686                         // Get response data
687                         if ( responses ) {
688                                 response = ajaxHandleResponses( s, jqXHR, responses );
689                         }
691                         // Convert no matter what (that way responseXXX fields are always set)
692                         response = ajaxConvert( s, response, jqXHR, isSuccess );
694                         // If successful, handle type chaining
695                         if ( isSuccess ) {
697                                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
698                                 if ( s.ifModified ) {
699                                         modified = jqXHR.getResponseHeader("Last-Modified");
700                                         if ( modified ) {
701                                                 jQuery.lastModified[ cacheURL ] = modified;
702                                         }
703                                         modified = jqXHR.getResponseHeader("etag");
704                                         if ( modified ) {
705                                                 jQuery.etag[ cacheURL ] = modified;
706                                         }
707                                 }
709                                 // if no content
710                                 if ( status === 204 || s.type === "HEAD" ) {
711                                         statusText = "nocontent";
713                                 // if not modified
714                                 } else if ( status === 304 ) {
715                                         statusText = "notmodified";
717                                 // If we have data, let's convert it
718                                 } else {
719                                         statusText = response.state;
720                                         success = response.data;
721                                         error = response.error;
722                                         isSuccess = !error;
723                                 }
724                         } else {
725                                 // We extract error from statusText
726                                 // then normalize statusText and status for non-aborts
727                                 error = statusText;
728                                 if ( status || !statusText ) {
729                                         statusText = "error";
730                                         if ( status < 0 ) {
731                                                 status = 0;
732                                         }
733                                 }
734                         }
736                         // Set data for the fake xhr object
737                         jqXHR.status = status;
738                         jqXHR.statusText = ( nativeStatusText || statusText ) + "";
740                         // Success/Error
741                         if ( isSuccess ) {
742                                 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
743                         } else {
744                                 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
745                         }
747                         // Status-dependent callbacks
748                         jqXHR.statusCode( statusCode );
749                         statusCode = undefined;
751                         if ( fireGlobals ) {
752                                 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
753                                         [ jqXHR, s, isSuccess ? success : error ] );
754                         }
756                         // Complete
757                         completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
759                         if ( fireGlobals ) {
760                                 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
761                                 // Handle the global AJAX counter
762                                 if ( !( --jQuery.active ) ) {
763                                         jQuery.event.trigger("ajaxStop");
764                                 }
765                         }
766                 }
768                 return jqXHR;
769         },
771         getJSON: function( url, data, callback ) {
772                 return jQuery.get( url, data, callback, "json" );
773         },
775         getScript: function( url, callback ) {
776                 return jQuery.get( url, undefined, callback, "script" );
777         }
780 jQuery.each( [ "get", "post" ], function( i, method ) {
781         jQuery[ method ] = function( url, data, callback, type ) {
782                 // shift arguments if data argument was omitted
783                 if ( jQuery.isFunction( data ) ) {
784                         type = type || callback;
785                         callback = data;
786                         data = undefined;
787                 }
789                 return jQuery.ajax({
790                         url: url,
791                         type: method,
792                         dataType: type,
793                         data: data,
794                         success: callback
795                 });
796         };
799 // Attach a bunch of functions for handling common AJAX events
800 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
801         jQuery.fn[ type ] = function( fn ) {
802                 return this.on( type, fn );
803         };
806 return jQuery;