Release: push dist to same remote as project
[jquery.git] / src / ajax.js
bloba9faee78d212489724450893c931e1915cea7051
1 define([
2         "./core",
3         "./var/document",
4         "./var/rnotwhite",
5         "./ajax/var/location",
6         "./ajax/var/nonce",
7         "./ajax/var/rquery",
8         "./core/init",
9         "./ajax/parseJSON",
10         "./ajax/parseXML",
11         "./deferred"
12 ], function( jQuery, document, rnotwhite, location, nonce, rquery ) {
14 var
15         rhash = /#.*$/,
16         rts = /([?&])_=[^&]*/,
17         rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
18         // #7653, #8125, #8152: local protocol detection
19         rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
20         rnoContent = /^(?:GET|HEAD)$/,
21         rprotocol = /^\/\//,
23         /* Prefilters
24          * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
25          * 2) These are called:
26          *    - BEFORE asking for a transport
27          *    - AFTER param serialization (s.data is a string if s.processData is true)
28          * 3) key is the dataType
29          * 4) the catchall symbol "*" can be used
30          * 5) execution will start with transport dataType and THEN continue down to "*" if needed
31          */
32         prefilters = {},
34         /* Transports bindings
35          * 1) key is the dataType
36          * 2) the catchall symbol "*" can be used
37          * 3) selection will start with transport dataType and THEN go to "*" if needed
38          */
39         transports = {},
41         // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
42         allTypes = "*/".concat( "*" ),
44         // Anchor tag for parsing the document origin
45         originAnchor = document.createElement( "a" );
46         originAnchor.href = location.href;
48 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
49 function addToPrefiltersOrTransports( structure ) {
51         // dataTypeExpression is optional and defaults to "*"
52         return function( dataTypeExpression, func ) {
54                 if ( typeof dataTypeExpression !== "string" ) {
55                         func = dataTypeExpression;
56                         dataTypeExpression = "*";
57                 }
59                 var dataType,
60                         i = 0,
61                         dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
63                 if ( jQuery.isFunction( func ) ) {
64                         // For each dataType in the dataTypeExpression
65                         while ( (dataType = dataTypes[i++]) ) {
66                                 // Prepend if requested
67                                 if ( dataType[0] === "+" ) {
68                                         dataType = dataType.slice( 1 ) || "*";
69                                         (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
71                                 // Otherwise append
72                                 } else {
73                                         (structure[ dataType ] = structure[ dataType ] || []).push( func );
74                                 }
75                         }
76                 }
77         };
80 // Base inspection function for prefilters and transports
81 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
83         var inspected = {},
84                 seekingTransport = ( structure === transports );
86         function inspect( dataType ) {
87                 var selected;
88                 inspected[ dataType ] = true;
89                 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
90                         var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
91                         if ( typeof dataTypeOrTransport === "string" &&
92                                 !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
94                                 options.dataTypes.unshift( dataTypeOrTransport );
95                                 inspect( dataTypeOrTransport );
96                                 return false;
97                         } else if ( seekingTransport ) {
98                                 return !( selected = dataTypeOrTransport );
99                         }
100                 });
101                 return selected;
102         }
104         return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
107 // A special extend for ajax options
108 // that takes "flat" options (not to be deep extended)
109 // Fixes #9887
110 function ajaxExtend( target, src ) {
111         var key, deep,
112                 flatOptions = jQuery.ajaxSettings.flatOptions || {};
114         for ( key in src ) {
115                 if ( src[ key ] !== undefined ) {
116                         ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
117                 }
118         }
119         if ( deep ) {
120                 jQuery.extend( true, target, deep );
121         }
123         return target;
126 /* Handles responses to an ajax request:
127  * - finds the right dataType (mediates between content-type and expected dataType)
128  * - returns the corresponding response
129  */
130 function ajaxHandleResponses( s, jqXHR, responses ) {
132         var ct, type, finalDataType, firstDataType,
133                 contents = s.contents,
134                 dataTypes = s.dataTypes;
136         // Remove auto dataType and get content-type in the process
137         while ( dataTypes[ 0 ] === "*" ) {
138                 dataTypes.shift();
139                 if ( ct === undefined ) {
140                         ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
141                 }
142         }
144         // Check if we're dealing with a known content-type
145         if ( ct ) {
146                 for ( type in contents ) {
147                         if ( contents[ type ] && contents[ type ].test( ct ) ) {
148                                 dataTypes.unshift( type );
149                                 break;
150                         }
151                 }
152         }
154         // Check to see if we have a response for the expected dataType
155         if ( dataTypes[ 0 ] in responses ) {
156                 finalDataType = dataTypes[ 0 ];
157         } else {
158                 // Try convertible dataTypes
159                 for ( type in responses ) {
160                         if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
161                                 finalDataType = type;
162                                 break;
163                         }
164                         if ( !firstDataType ) {
165                                 firstDataType = type;
166                         }
167                 }
168                 // Or just use first one
169                 finalDataType = finalDataType || firstDataType;
170         }
172         // If we found a dataType
173         // We add the dataType to the list if needed
174         // and return the corresponding response
175         if ( finalDataType ) {
176                 if ( finalDataType !== dataTypes[ 0 ] ) {
177                         dataTypes.unshift( finalDataType );
178                 }
179                 return responses[ finalDataType ];
180         }
183 /* Chain conversions given the request and the original response
184  * Also sets the responseXXX fields on the jqXHR instance
185  */
186 function ajaxConvert( s, response, jqXHR, isSuccess ) {
187         var conv2, current, conv, tmp, prev,
188                 converters = {},
189                 // Work with a copy of dataTypes in case we need to modify it for conversion
190                 dataTypes = s.dataTypes.slice();
192         // Create converters map with lowercased keys
193         if ( dataTypes[ 1 ] ) {
194                 for ( conv in s.converters ) {
195                         converters[ conv.toLowerCase() ] = s.converters[ conv ];
196                 }
197         }
199         current = dataTypes.shift();
201         // Convert to each sequential dataType
202         while ( current ) {
204                 if ( s.responseFields[ current ] ) {
205                         jqXHR[ s.responseFields[ current ] ] = response;
206                 }
208                 // Apply the dataFilter if provided
209                 if ( !prev && isSuccess && s.dataFilter ) {
210                         response = s.dataFilter( response, s.dataType );
211                 }
213                 prev = current;
214                 current = dataTypes.shift();
216                 if ( current ) {
218                 // There's only work to do if current dataType is non-auto
219                         if ( current === "*" ) {
221                                 current = prev;
223                         // Convert response if prev dataType is non-auto and differs from current
224                         } else if ( prev !== "*" && prev !== current ) {
226                                 // Seek a direct converter
227                                 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
229                                 // If none found, seek a pair
230                                 if ( !conv ) {
231                                         for ( conv2 in converters ) {
233                                                 // If conv2 outputs current
234                                                 tmp = conv2.split( " " );
235                                                 if ( tmp[ 1 ] === current ) {
237                                                         // If prev can be converted to accepted input
238                                                         conv = converters[ prev + " " + tmp[ 0 ] ] ||
239                                                                 converters[ "* " + tmp[ 0 ] ];
240                                                         if ( conv ) {
241                                                                 // Condense equivalence converters
242                                                                 if ( conv === true ) {
243                                                                         conv = converters[ conv2 ];
245                                                                 // Otherwise, insert the intermediate dataType
246                                                                 } else if ( converters[ conv2 ] !== true ) {
247                                                                         current = tmp[ 0 ];
248                                                                         dataTypes.unshift( tmp[ 1 ] );
249                                                                 }
250                                                                 break;
251                                                         }
252                                                 }
253                                         }
254                                 }
256                                 // Apply converter (if not an equivalence)
257                                 if ( conv !== true ) {
259                                         // Unless errors are allowed to bubble, catch and return them
260                                         if ( conv && s[ "throws" ] ) {
261                                                 response = conv( response );
262                                         } else {
263                                                 try {
264                                                         response = conv( response );
265                                                 } catch ( e ) {
266                                                         return {
267                                                                 state: "parsererror",
268                                                                 error: conv ? e : "No conversion from " + prev + " to " + current
269                                                         };
270                                                 }
271                                         }
272                                 }
273                         }
274                 }
275         }
277         return { state: "success", data: response };
280 jQuery.extend({
282         // Counter for holding the number of active queries
283         active: 0,
285         // Last-Modified header cache for next request
286         lastModified: {},
287         etag: {},
289         ajaxSettings: {
290                 url: location.href,
291                 type: "GET",
292                 isLocal: rlocalProtocol.test( location.protocol ),
293                 global: true,
294                 processData: true,
295                 async: true,
296                 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
297                 /*
298                 timeout: 0,
299                 data: null,
300                 dataType: null,
301                 username: null,
302                 password: null,
303                 cache: null,
304                 throws: false,
305                 traditional: false,
306                 headers: {},
307                 */
309                 accepts: {
310                         "*": allTypes,
311                         text: "text/plain",
312                         html: "text/html",
313                         xml: "application/xml, text/xml",
314                         json: "application/json, text/javascript"
315                 },
317                 contents: {
318                         xml: /xml/,
319                         html: /html/,
320                         json: /json/
321                 },
323                 responseFields: {
324                         xml: "responseXML",
325                         text: "responseText",
326                         json: "responseJSON"
327                 },
329                 // Data converters
330                 // Keys separate source (or catchall "*") and destination types with a single space
331                 converters: {
333                         // Convert anything to text
334                         "* text": String,
336                         // Text to html (true = no transformation)
337                         "text html": true,
339                         // Evaluate text as a json expression
340                         "text json": jQuery.parseJSON,
342                         // Parse text as xml
343                         "text xml": jQuery.parseXML
344                 },
346                 // For options that shouldn't be deep extended:
347                 // you can add your own custom options here if
348                 // and when you create one that shouldn't be
349                 // deep extended (see ajaxExtend)
350                 flatOptions: {
351                         url: true,
352                         context: true
353                 }
354         },
356         // Creates a full fledged settings object into target
357         // with both ajaxSettings and settings fields.
358         // If target is omitted, writes into ajaxSettings.
359         ajaxSetup: function( target, settings ) {
360                 return settings ?
362                         // Building a settings object
363                         ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
365                         // Extending ajaxSettings
366                         ajaxExtend( jQuery.ajaxSettings, target );
367         },
369         ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
370         ajaxTransport: addToPrefiltersOrTransports( transports ),
372         // Main method
373         ajax: function( url, options ) {
375                 // If url is an object, simulate pre-1.5 signature
376                 if ( typeof url === "object" ) {
377                         options = url;
378                         url = undefined;
379                 }
381                 // Force options to be an object
382                 options = options || {};
384                 var transport,
385                         // URL without anti-cache param
386                         cacheURL,
387                         // Response headers
388                         responseHeadersString,
389                         responseHeaders,
390                         // timeout handle
391                         timeoutTimer,
392                         // Url cleanup var
393                         urlAnchor,
394                         // To know if global events are to be dispatched
395                         fireGlobals,
396                         // Loop variable
397                         i,
398                         // Create the final options object
399                         s = jQuery.ajaxSetup( {}, options ),
400                         // Callbacks context
401                         callbackContext = s.context || s,
402                         // Context for global events is callbackContext if it is a DOM node or jQuery collection
403                         globalEventContext = s.context &&
404                                 ( callbackContext.nodeType || callbackContext.jquery ) ?
405                                         jQuery( callbackContext ) :
406                                         jQuery.event,
407                         // Deferreds
408                         deferred = jQuery.Deferred(),
409                         completeDeferred = jQuery.Callbacks("once memory"),
410                         // Status-dependent callbacks
411                         statusCode = s.statusCode || {},
412                         // Headers (they are sent all at once)
413                         requestHeaders = {},
414                         requestHeadersNames = {},
415                         // The jqXHR state
416                         state = 0,
417                         // Default abort message
418                         strAbort = "canceled",
419                         // Fake xhr
420                         jqXHR = {
421                                 readyState: 0,
423                                 // Builds headers hashtable if needed
424                                 getResponseHeader: function( key ) {
425                                         var match;
426                                         if ( state === 2 ) {
427                                                 if ( !responseHeaders ) {
428                                                         responseHeaders = {};
429                                                         while ( (match = rheaders.exec( responseHeadersString )) ) {
430                                                                 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
431                                                         }
432                                                 }
433                                                 match = responseHeaders[ key.toLowerCase() ];
434                                         }
435                                         return match == null ? null : match;
436                                 },
438                                 // Raw string
439                                 getAllResponseHeaders: function() {
440                                         return state === 2 ? responseHeadersString : null;
441                                 },
443                                 // Caches the header
444                                 setRequestHeader: function( name, value ) {
445                                         var lname = name.toLowerCase();
446                                         if ( !state ) {
447                                                 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
448                                                 requestHeaders[ name ] = value;
449                                         }
450                                         return this;
451                                 },
453                                 // Overrides response content-type header
454                                 overrideMimeType: function( type ) {
455                                         if ( !state ) {
456                                                 s.mimeType = type;
457                                         }
458                                         return this;
459                                 },
461                                 // Status-dependent callbacks
462                                 statusCode: function( map ) {
463                                         var code;
464                                         if ( map ) {
465                                                 if ( state < 2 ) {
466                                                         for ( code in map ) {
467                                                                 // Lazy-add the new callback in a way that preserves old ones
468                                                                 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
469                                                         }
470                                                 } else {
471                                                         // Execute the appropriate callbacks
472                                                         jqXHR.always( map[ jqXHR.status ] );
473                                                 }
474                                         }
475                                         return this;
476                                 },
478                                 // Cancel the request
479                                 abort: function( statusText ) {
480                                         var finalText = statusText || strAbort;
481                                         if ( transport ) {
482                                                 transport.abort( finalText );
483                                         }
484                                         done( 0, finalText );
485                                         return this;
486                                 }
487                         };
489                 // Attach deferreds
490                 deferred.promise( jqXHR ).complete = completeDeferred.add;
491                 jqXHR.success = jqXHR.done;
492                 jqXHR.error = jqXHR.fail;
494                 // Remove hash character (#7531: and string promotion)
495                 // Add protocol if not provided (prefilters might expect it)
496                 // Handle falsy url in the settings object (#10093: consistency with old signature)
497                 // We also use the url parameter if available
498                 s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" )
499                         .replace( rprotocol, location.protocol + "//" );
501                 // Alias method option to type as per ticket #12004
502                 s.type = options.method || options.type || s.method || s.type;
504                 // Extract dataTypes list
505                 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
507                 // A cross-domain request is in order when the origin doesn't match the current origin.
508                 if ( s.crossDomain == null ) {
509                         urlAnchor = document.createElement( "a" );
511                         // Support: IE8-11+
512                         // IE throws exception if url is malformed, e.g. http://example.com:80x/
513                         try {
514                                 urlAnchor.href = s.url;
515                                 // Support: IE8-11+
516                                 // Anchor's host property isn't correctly set when s.url is relative
517                                 urlAnchor.href = urlAnchor.href;
518                                 s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
519                                         urlAnchor.protocol + "//" + urlAnchor.host;
520                         } catch ( e ) {
521                                 // If there is an error parsing the URL, assume it is crossDomain,
522                                 // it can be rejected by the transport if it is invalid
523                                 s.crossDomain = true;
524                         }
525                 }
527                 // Convert data if not already a string
528                 if ( s.data && s.processData && typeof s.data !== "string" ) {
529                         s.data = jQuery.param( s.data, s.traditional );
530                 }
532                 // Apply prefilters
533                 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
535                 // If request was aborted inside a prefilter, stop there
536                 if ( state === 2 ) {
537                         return jqXHR;
538                 }
540                 // We can fire global events as of now if asked to
541                 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
542                 fireGlobals = jQuery.event && s.global;
544                 // Watch for a new set of requests
545                 if ( fireGlobals && jQuery.active++ === 0 ) {
546                         jQuery.event.trigger("ajaxStart");
547                 }
549                 // Uppercase the type
550                 s.type = s.type.toUpperCase();
552                 // Determine if request has content
553                 s.hasContent = !rnoContent.test( s.type );
555                 // Save the URL in case we're toying with the If-Modified-Since
556                 // and/or If-None-Match header later on
557                 cacheURL = s.url;
559                 // More options handling for requests with no content
560                 if ( !s.hasContent ) {
562                         // If data is available, append data to url
563                         if ( s.data ) {
564                                 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
565                                 // #9682: remove data so that it's not used in an eventual retry
566                                 delete s.data;
567                         }
569                         // Add anti-cache in url if needed
570                         if ( s.cache === false ) {
571                                 s.url = rts.test( cacheURL ) ?
573                                         // If there is already a '_' parameter, set its value
574                                         cacheURL.replace( rts, "$1_=" + nonce++ ) :
576                                         // Otherwise add one to the end
577                                         cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
578                         }
579                 }
581                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
582                 if ( s.ifModified ) {
583                         if ( jQuery.lastModified[ cacheURL ] ) {
584                                 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
585                         }
586                         if ( jQuery.etag[ cacheURL ] ) {
587                                 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
588                         }
589                 }
591                 // Set the correct header, if data is being sent
592                 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
593                         jqXHR.setRequestHeader( "Content-Type", s.contentType );
594                 }
596                 // Set the Accepts header for the server, depending on the dataType
597                 jqXHR.setRequestHeader(
598                         "Accept",
599                         s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
600                                 s.accepts[ s.dataTypes[0] ] +
601                                         ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
602                                 s.accepts[ "*" ]
603                 );
605                 // Check for headers option
606                 for ( i in s.headers ) {
607                         jqXHR.setRequestHeader( i, s.headers[ i ] );
608                 }
610                 // Allow custom headers/mimetypes and early abort
611                 if ( s.beforeSend &&
612                         ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
614                         // Abort if not done already and return
615                         return jqXHR.abort();
616                 }
618                 // Aborting is no longer a cancellation
619                 strAbort = "abort";
621                 // Install callbacks on deferreds
622                 for ( i in { success: 1, error: 1, complete: 1 } ) {
623                         jqXHR[ i ]( s[ i ] );
624                 }
626                 // Get transport
627                 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
629                 // If no transport, we auto-abort
630                 if ( !transport ) {
631                         done( -1, "No Transport" );
632                 } else {
633                         jqXHR.readyState = 1;
635                         // Send global event
636                         if ( fireGlobals ) {
637                                 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
638                         }
640                         // If request was aborted inside ajaxSend, stop there
641                         if ( state === 2 ) {
642                                 return jqXHR;
643                         }
645                         // Timeout
646                         if ( s.async && s.timeout > 0 ) {
647                                 timeoutTimer = setTimeout(function() {
648                                         jqXHR.abort("timeout");
649                                 }, s.timeout );
650                         }
652                         try {
653                                 state = 1;
654                                 transport.send( requestHeaders, done );
655                         } catch ( e ) {
656                                 // Propagate exception as error if not done
657                                 if ( state < 2 ) {
658                                         done( -1, e );
659                                 // Simply rethrow otherwise
660                                 } else {
661                                         throw e;
662                                 }
663                         }
664                 }
666                 // Callback for when everything is done
667                 function done( status, nativeStatusText, responses, headers ) {
668                         var isSuccess, success, error, response, modified,
669                                 statusText = nativeStatusText;
671                         // Called once
672                         if ( state === 2 ) {
673                                 return;
674                         }
676                         // State is "done" now
677                         state = 2;
679                         // Clear timeout if it exists
680                         if ( timeoutTimer ) {
681                                 clearTimeout( timeoutTimer );
682                         }
684                         // Dereference transport for early garbage collection
685                         // (no matter how long the jqXHR object will be used)
686                         transport = undefined;
688                         // Cache response headers
689                         responseHeadersString = headers || "";
691                         // Set readyState
692                         jqXHR.readyState = status > 0 ? 4 : 0;
694                         // Determine if successful
695                         isSuccess = status >= 200 && status < 300 || status === 304;
697                         // Get response data
698                         if ( responses ) {
699                                 response = ajaxHandleResponses( s, jqXHR, responses );
700                         }
702                         // Convert no matter what (that way responseXXX fields are always set)
703                         response = ajaxConvert( s, response, jqXHR, isSuccess );
705                         // If successful, handle type chaining
706                         if ( isSuccess ) {
708                                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
709                                 if ( s.ifModified ) {
710                                         modified = jqXHR.getResponseHeader("Last-Modified");
711                                         if ( modified ) {
712                                                 jQuery.lastModified[ cacheURL ] = modified;
713                                         }
714                                         modified = jqXHR.getResponseHeader("etag");
715                                         if ( modified ) {
716                                                 jQuery.etag[ cacheURL ] = modified;
717                                         }
718                                 }
720                                 // if no content
721                                 if ( status === 204 || s.type === "HEAD" ) {
722                                         statusText = "nocontent";
724                                 // if not modified
725                                 } else if ( status === 304 ) {
726                                         statusText = "notmodified";
728                                 // If we have data, let's convert it
729                                 } else {
730                                         statusText = response.state;
731                                         success = response.data;
732                                         error = response.error;
733                                         isSuccess = !error;
734                                 }
735                         } else {
736                                 // Extract error from statusText and normalize for non-aborts
737                                 error = statusText;
738                                 if ( status || !statusText ) {
739                                         statusText = "error";
740                                         if ( status < 0 ) {
741                                                 status = 0;
742                                         }
743                                 }
744                         }
746                         // Set data for the fake xhr object
747                         jqXHR.status = status;
748                         jqXHR.statusText = ( nativeStatusText || statusText ) + "";
750                         // Success/Error
751                         if ( isSuccess ) {
752                                 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
753                         } else {
754                                 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
755                         }
757                         // Status-dependent callbacks
758                         jqXHR.statusCode( statusCode );
759                         statusCode = undefined;
761                         if ( fireGlobals ) {
762                                 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
763                                         [ jqXHR, s, isSuccess ? success : error ] );
764                         }
766                         // Complete
767                         completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
769                         if ( fireGlobals ) {
770                                 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
771                                 // Handle the global AJAX counter
772                                 if ( !( --jQuery.active ) ) {
773                                         jQuery.event.trigger("ajaxStop");
774                                 }
775                         }
776                 }
778                 return jqXHR;
779         },
781         getJSON: function( url, data, callback ) {
782                 return jQuery.get( url, data, callback, "json" );
783         },
785         getScript: function( url, callback ) {
786                 return jQuery.get( url, undefined, callback, "script" );
787         }
790 jQuery.each( [ "get", "post" ], function( i, method ) {
791         jQuery[ method ] = function( url, data, callback, type ) {
792                 // Shift arguments if data argument was omitted
793                 if ( jQuery.isFunction( data ) ) {
794                         type = type || callback;
795                         callback = data;
796                         data = undefined;
797                 }
799                 // The url can be an options object (which then must have .url)
800                 return jQuery.ajax( jQuery.extend({
801                         url: url,
802                         type: method,
803                         dataType: type,
804                         data: data,
805                         success: callback
806                 }, jQuery.isPlainObject( url ) && url ) );
807         };
810 return jQuery;