Effects: set default easing using jQuery.easing._default
[jquery.git] / src / ajax.js
blob24425bac6ba7ffe8380c8210cad3468cce868bda
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         rhash = /#.*$/,
14         rts = /([?&])_=[^&]*/,
15         rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
16         // #7653, #8125, #8152: local protocol detection
17         rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
18         rnoContent = /^(?:GET|HEAD)$/,
19         rprotocol = /^\/\//,
21         /* Prefilters
22          * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
23          * 2) These are called:
24          *    - BEFORE asking for a transport
25          *    - AFTER param serialization (s.data is a string if s.processData is true)
26          * 3) key is the dataType
27          * 4) the catchall symbol "*" can be used
28          * 5) execution will start with transport dataType and THEN continue down to "*" if needed
29          */
30         prefilters = {},
32         /* Transports bindings
33          * 1) key is the dataType
34          * 2) the catchall symbol "*" can be used
35          * 3) selection will start with transport dataType and THEN go to "*" if needed
36          */
37         transports = {},
39         // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
40         allTypes = "*/".concat( "*" ),
42         // Anchor tag for parsing the document origin
43         originAnchor = document.createElement( "a" );
45         originAnchor.href = location.href;
47 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
48 function addToPrefiltersOrTransports( structure ) {
50         // dataTypeExpression is optional and defaults to "*"
51         return function( dataTypeExpression, func ) {
53                 if ( typeof dataTypeExpression !== "string" ) {
54                         func = dataTypeExpression;
55                         dataTypeExpression = "*";
56                 }
58                 var dataType,
59                         i = 0,
60                         dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
62                 if ( jQuery.isFunction( func ) ) {
63                         // For each dataType in the dataTypeExpression
64                         while ( (dataType = dataTypes[i++]) ) {
65                                 // Prepend if requested
66                                 if ( dataType[ 0 ] === "+" ) {
67                                         dataType = dataType.slice( 1 ) || "*";
68                                         (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
70                                 // Otherwise append
71                                 } else {
72                                         (structure[ dataType ] = structure[ dataType ] || []).push( func );
73                                 }
74                         }
75                 }
76         };
79 // Base inspection function for prefilters and transports
80 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
82         var inspected = {},
83                 seekingTransport = ( structure === transports );
85         function inspect( dataType ) {
86                 var selected;
87                 inspected[ dataType ] = true;
88                 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
89                         var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
90                         if ( typeof dataTypeOrTransport === "string" &&
91                                 !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
93                                 options.dataTypes.unshift( dataTypeOrTransport );
94                                 inspect( dataTypeOrTransport );
95                                 return false;
96                         } else if ( seekingTransport ) {
97                                 return !( selected = dataTypeOrTransport );
98                         }
99                 });
100                 return selected;
101         }
103         return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
106 // A special extend for ajax options
107 // that takes "flat" options (not to be deep extended)
108 // Fixes #9887
109 function ajaxExtend( target, src ) {
110         var deep, key,
111                 flatOptions = jQuery.ajaxSettings.flatOptions || {};
113         for ( key in src ) {
114                 if ( src[ key ] !== undefined ) {
115                         ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
116                 }
117         }
118         if ( deep ) {
119                 jQuery.extend( true, target, deep );
120         }
122         return target;
125 /* Handles responses to an ajax request:
126  * - finds the right dataType (mediates between content-type and expected dataType)
127  * - returns the corresponding response
128  */
129 function ajaxHandleResponses( s, jqXHR, responses ) {
130         var firstDataType, ct, finalDataType, type,
131                 contents = s.contents,
132                 dataTypes = s.dataTypes;
134         // Remove auto dataType and get content-type in the process
135         while ( dataTypes[ 0 ] === "*" ) {
136                 dataTypes.shift();
137                 if ( ct === undefined ) {
138                         ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
139                 }
140         }
142         // Check if we're dealing with a known content-type
143         if ( ct ) {
144                 for ( type in contents ) {
145                         if ( contents[ type ] && contents[ type ].test( ct ) ) {
146                                 dataTypes.unshift( type );
147                                 break;
148                         }
149                 }
150         }
152         // Check to see if we have a response for the expected dataType
153         if ( dataTypes[ 0 ] in responses ) {
154                 finalDataType = dataTypes[ 0 ];
155         } else {
156                 // Try convertible dataTypes
157                 for ( type in responses ) {
158                         if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
159                                 finalDataType = type;
160                                 break;
161                         }
162                         if ( !firstDataType ) {
163                                 firstDataType = type;
164                         }
165                 }
166                 // Or just use first one
167                 finalDataType = finalDataType || firstDataType;
168         }
170         // If we found a dataType
171         // We add the dataType to the list if needed
172         // and return the corresponding response
173         if ( finalDataType ) {
174                 if ( finalDataType !== dataTypes[ 0 ] ) {
175                         dataTypes.unshift( finalDataType );
176                 }
177                 return responses[ finalDataType ];
178         }
181 /* Chain conversions given the request and the original response
182  * Also sets the responseXXX fields on the jqXHR instance
183  */
184 function ajaxConvert( s, response, jqXHR, isSuccess ) {
185         var conv2, current, conv, tmp, prev,
186                 converters = {},
187                 // Work with a copy of dataTypes in case we need to modify it for conversion
188                 dataTypes = s.dataTypes.slice();
190         // Create converters map with lowercased keys
191         if ( dataTypes[ 1 ] ) {
192                 for ( conv in s.converters ) {
193                         converters[ conv.toLowerCase() ] = s.converters[ conv ];
194                 }
195         }
197         current = dataTypes.shift();
199         // Convert to each sequential dataType
200         while ( current ) {
202                 if ( s.responseFields[ current ] ) {
203                         jqXHR[ s.responseFields[ current ] ] = response;
204                 }
206                 // Apply the dataFilter if provided
207                 if ( !prev && isSuccess && s.dataFilter ) {
208                         response = s.dataFilter( response, s.dataType );
209                 }
211                 prev = current;
212                 current = dataTypes.shift();
214                 if ( current ) {
216                         // There's only work to do if current dataType is non-auto
217                         if ( current === "*" ) {
219                                 current = prev;
221                         // Convert response if prev dataType is non-auto and differs from current
222                         } else if ( prev !== "*" && prev !== current ) {
224                                 // Seek a direct converter
225                                 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
227                                 // If none found, seek a pair
228                                 if ( !conv ) {
229                                         for ( conv2 in converters ) {
231                                                 // If conv2 outputs current
232                                                 tmp = conv2.split( " " );
233                                                 if ( tmp[ 1 ] === current ) {
235                                                         // If prev can be converted to accepted input
236                                                         conv = converters[ prev + " " + tmp[ 0 ] ] ||
237                                                                 converters[ "* " + tmp[ 0 ] ];
238                                                         if ( conv ) {
239                                                                 // Condense equivalence converters
240                                                                 if ( conv === true ) {
241                                                                         conv = converters[ conv2 ];
243                                                                 // Otherwise, insert the intermediate dataType
244                                                                 } else if ( converters[ conv2 ] !== true ) {
245                                                                         current = tmp[ 0 ];
246                                                                         dataTypes.unshift( tmp[ 1 ] );
247                                                                 }
248                                                                 break;
249                                                         }
250                                                 }
251                                         }
252                                 }
254                                 // Apply converter (if not an equivalence)
255                                 if ( conv !== true ) {
257                                         // Unless errors are allowed to bubble, catch and return them
258                                         if ( conv && s[ "throws" ] ) {
259                                                 response = conv( response );
260                                         } else {
261                                                 try {
262                                                         response = conv( response );
263                                                 } catch ( e ) {
264                                                         return {
265                                                                 state: "parsererror",
266                                                                 error: conv ? e : "No conversion from " + prev + " to " + current
267                                                         };
268                                                 }
269                                         }
270                                 }
271                         }
272                 }
273         }
275         return { state: "success", data: response };
278 jQuery.extend({
280         // Counter for holding the number of active queries
281         active: 0,
283         // Last-Modified header cache for next request
284         lastModified: {},
285         etag: {},
287         ajaxSettings: {
288                 url: location.href,
289                 type: "GET",
290                 isLocal: rlocalProtocol.test( location.protocol ),
291                 global: true,
292                 processData: true,
293                 async: true,
294                 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
295                 /*
296                 timeout: 0,
297                 data: null,
298                 dataType: null,
299                 username: null,
300                 password: null,
301                 cache: null,
302                 throws: false,
303                 traditional: false,
304                 headers: {},
305                 */
307                 accepts: {
308                         "*": allTypes,
309                         text: "text/plain",
310                         html: "text/html",
311                         xml: "application/xml, text/xml",
312                         json: "application/json, text/javascript"
313                 },
315                 contents: {
316                         xml: /xml/,
317                         html: /html/,
318                         json: /json/
319                 },
321                 responseFields: {
322                         xml: "responseXML",
323                         text: "responseText",
324                         json: "responseJSON"
325                 },
327                 // Data converters
328                 // Keys separate source (or catchall "*") and destination types with a single space
329                 converters: {
331                         // Convert anything to text
332                         "* text": String,
334                         // Text to html (true = no transformation)
335                         "text html": true,
337                         // Evaluate text as a json expression
338                         "text json": jQuery.parseJSON,
340                         // Parse text as xml
341                         "text xml": jQuery.parseXML
342                 },
344                 // For options that shouldn't be deep extended:
345                 // you can add your own custom options here if
346                 // and when you create one that shouldn't be
347                 // deep extended (see ajaxExtend)
348                 flatOptions: {
349                         url: true,
350                         context: true
351                 }
352         },
354         // Creates a full fledged settings object into target
355         // with both ajaxSettings and settings fields.
356         // If target is omitted, writes into ajaxSettings.
357         ajaxSetup: function( target, settings ) {
358                 return settings ?
360                         // Building a settings object
361                         ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
363                         // Extending ajaxSettings
364                         ajaxExtend( jQuery.ajaxSettings, target );
365         },
367         ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
368         ajaxTransport: addToPrefiltersOrTransports( transports ),
370         // Main method
371         ajax: function( url, options ) {
373                 // If url is an object, simulate pre-1.5 signature
374                 if ( typeof url === "object" ) {
375                         options = url;
376                         url = undefined;
377                 }
379                 // Force options to be an object
380                 options = options || {};
382                 var
383                         // Loop variable
384                         i,
385                         // URL without anti-cache param
386                         cacheURL,
387                         // Response headers as string
388                         responseHeadersString,
389                         // timeout handle
390                         timeoutTimer,
391                         // Url cleanup var
392                         urlAnchor,
393                         // To know if global events are to be dispatched
394                         fireGlobals,
396                         transport,
397                         // Response headers
398                         responseHeaders,
399                         // Create the final options object
400                         s = jQuery.ajaxSetup( {}, options ),
401                         // Callbacks context
402                         callbackContext = s.context || s,
403                         // Context for global events is callbackContext if it is a DOM node or jQuery collection
404                         globalEventContext = s.context &&
405                                 ( callbackContext.nodeType || callbackContext.jquery ) ?
406                                         jQuery( callbackContext ) :
407                                         jQuery.event,
408                         // Deferreds
409                         deferred = jQuery.Deferred(),
410                         completeDeferred = jQuery.Callbacks("once memory"),
411                         // Status-dependent callbacks
412                         statusCode = s.statusCode || {},
413                         // Headers (they are sent all at once)
414                         requestHeaders = {},
415                         requestHeadersNames = {},
416                         // The jqXHR state
417                         state = 0,
418                         // Default abort message
419                         strAbort = "canceled",
420                         // Fake xhr
421                         jqXHR = {
422                                 readyState: 0,
424                                 // Builds headers hashtable if needed
425                                 getResponseHeader: function( key ) {
426                                         var match;
427                                         if ( state === 2 ) {
428                                                 if ( !responseHeaders ) {
429                                                         responseHeaders = {};
430                                                         while ( (match = rheaders.exec( responseHeadersString )) ) {
431                                                                 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
432                                                         }
433                                                 }
434                                                 match = responseHeaders[ key.toLowerCase() ];
435                                         }
436                                         return match == null ? null : match;
437                                 },
439                                 // Raw string
440                                 getAllResponseHeaders: function() {
441                                         return state === 2 ? responseHeadersString : null;
442                                 },
444                                 // Caches the header
445                                 setRequestHeader: function( name, value ) {
446                                         var lname = name.toLowerCase();
447                                         if ( !state ) {
448                                                 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
449                                                 requestHeaders[ name ] = value;
450                                         }
451                                         return this;
452                                 },
454                                 // Overrides response content-type header
455                                 overrideMimeType: function( type ) {
456                                         if ( !state ) {
457                                                 s.mimeType = type;
458                                         }
459                                         return this;
460                                 },
462                                 // Status-dependent callbacks
463                                 statusCode: function( map ) {
464                                         var code;
465                                         if ( map ) {
466                                                 if ( state < 2 ) {
467                                                         for ( code in map ) {
468                                                                 // Lazy-add the new callback in a way that preserves old ones
469                                                                 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
470                                                         }
471                                                 } else {
472                                                         // Execute the appropriate callbacks
473                                                         jqXHR.always( map[ jqXHR.status ] );
474                                                 }
475                                         }
476                                         return this;
477                                 },
479                                 // Cancel the request
480                                 abort: function( statusText ) {
481                                         var finalText = statusText || strAbort;
482                                         if ( transport ) {
483                                                 transport.abort( finalText );
484                                         }
485                                         done( 0, finalText );
486                                         return this;
487                                 }
488                         };
490                 // Attach deferreds
491                 deferred.promise( jqXHR );
493                 // Remove hash character (#7531: and string promotion)
494                 // Add protocol if not provided (prefilters might expect it)
495                 // Handle falsy url in the settings object (#10093: consistency with old signature)
496                 // We also use the url parameter if available
497                 s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" )
498                         .replace( rprotocol, location.protocol + "//" );
500                 // Alias method option to type as per ticket #12004
501                 s.type = options.method || options.type || s.method || s.type;
503                 // Extract dataTypes list
504                 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
506                 // A cross-domain request is in order when the origin doesn't match the current origin
507                 if ( s.crossDomain == null ) {
508                         urlAnchor = document.createElement( "a" );
510                         // Support: IE8-11+
511                         // IE throws exception if url is malformed, e.g. http://example.com:80x/
512                         try {
513                                 urlAnchor.href = s.url;
514                                 // Support: IE8-11+
515                                 // Anchor's host property isn't correctly set when s.url is relative
516                                 urlAnchor.href = urlAnchor.href;
517                                 s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
518                                         urlAnchor.protocol + "//" + urlAnchor.host;
519                         } catch ( e ) {
520                                 // If there is an error parsing the URL, assume it is crossDomain,
521                                 // it can be rejected by the transport if it is invalid
522                                 s.crossDomain = true;
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                 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
541                 fireGlobals = jQuery.event && s.global;
543                 // Watch for a new set of requests
544                 if ( fireGlobals && jQuery.active++ === 0 ) {
545                         jQuery.event.trigger("ajaxStart");
546                 }
548                 // Uppercase the type
549                 s.type = s.type.toUpperCase();
551                 // Determine if request has content
552                 s.hasContent = !rnoContent.test( s.type );
554                 // Save the URL in case we're toying with the If-Modified-Since
555                 // and/or If-None-Match header later on
556                 cacheURL = s.url;
558                 // More options handling for requests with no content
559                 if ( !s.hasContent ) {
561                         // If data is available, append data to url
562                         if ( s.data ) {
563                                 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
564                                 // #9682: remove data so that it's not used in an eventual retry
565                                 delete s.data;
566                         }
568                         // Add anti-cache in url if needed
569                         if ( s.cache === false ) {
570                                 s.url = rts.test( cacheURL ) ?
572                                         // If there is already a '_' parameter, set its value
573                                         cacheURL.replace( rts, "$1_=" + nonce++ ) :
575                                         // Otherwise add one to the end
576                                         cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
577                         }
578                 }
580                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
581                 if ( s.ifModified ) {
582                         if ( jQuery.lastModified[ cacheURL ] ) {
583                                 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
584                         }
585                         if ( jQuery.etag[ cacheURL ] ) {
586                                 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
587                         }
588                 }
590                 // Set the correct header, if data is being sent
591                 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
592                         jqXHR.setRequestHeader( "Content-Type", s.contentType );
593                 }
595                 // Set the Accepts header for the server, depending on the dataType
596                 jqXHR.setRequestHeader(
597                         "Accept",
598                         s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
599                                 s.accepts[ s.dataTypes[0] ] +
600                                         ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
601                                 s.accepts[ "*" ]
602                 );
604                 // Check for headers option
605                 for ( i in s.headers ) {
606                         jqXHR.setRequestHeader( i, s.headers[ i ] );
607                 }
609                 // Allow custom headers/mimetypes and early abort
610                 if ( s.beforeSend &&
611                         ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
613                         // Abort if not done already and return
614                         return jqXHR.abort();
615                 }
617                 // aborting is no longer a cancellation
618                 strAbort = "abort";
620                 // Install callbacks on deferreds
621                 completeDeferred.add( s.complete );
622                 jqXHR.done( s.success );
623                 jqXHR.fail( s.error );
625                 // Get transport
626                 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
628                 // If no transport, we auto-abort
629                 if ( !transport ) {
630                         done( -1, "No Transport" );
631                 } else {
632                         jqXHR.readyState = 1;
634                         // Send global event
635                         if ( fireGlobals ) {
636                                 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
637                         }
639                         // If request was aborted inside ajaxSend, stop there
640                         if ( state === 2 ) {
641                                 return jqXHR;
642                         }
644                         // Timeout
645                         if ( s.async && s.timeout > 0 ) {
646                                 timeoutTimer = setTimeout(function() {
647                                         jqXHR.abort("timeout");
648                                 }, s.timeout );
649                         }
651                         try {
652                                 state = 1;
653                                 transport.send( requestHeaders, done );
654                         } catch ( e ) {
655                                 // Propagate exception as error if not done
656                                 if ( state < 2 ) {
657                                         done( -1, e );
658                                 // Simply rethrow otherwise
659                                 } else {
660                                         throw e;
661                                 }
662                         }
663                 }
665                 // Callback for when everything is done
666                 function done( status, nativeStatusText, responses, headers ) {
667                         var isSuccess, success, error, response, modified,
668                                 statusText = nativeStatusText;
670                         // Called once
671                         if ( state === 2 ) {
672                                 return;
673                         }
675                         // State is "done" now
676                         state = 2;
678                         // Clear timeout if it exists
679                         if ( timeoutTimer ) {
680                                 clearTimeout( timeoutTimer );
681                         }
683                         // Dereference transport for early garbage collection
684                         // (no matter how long the jqXHR object will be used)
685                         transport = undefined;
687                         // Cache response headers
688                         responseHeadersString = headers || "";
690                         // Set readyState
691                         jqXHR.readyState = status > 0 ? 4 : 0;
693                         // Determine if successful
694                         isSuccess = status >= 200 && status < 300 || status === 304;
696                         // Get response data
697                         if ( responses ) {
698                                 response = ajaxHandleResponses( s, jqXHR, responses );
699                         }
701                         // Convert no matter what (that way responseXXX fields are always set)
702                         response = ajaxConvert( s, response, jqXHR, isSuccess );
704                         // If successful, handle type chaining
705                         if ( isSuccess ) {
707                                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
708                                 if ( s.ifModified ) {
709                                         modified = jqXHR.getResponseHeader("Last-Modified");
710                                         if ( modified ) {
711                                                 jQuery.lastModified[ cacheURL ] = modified;
712                                         }
713                                         modified = jqXHR.getResponseHeader("etag");
714                                         if ( modified ) {
715                                                 jQuery.etag[ cacheURL ] = modified;
716                                         }
717                                 }
719                                 // if no content
720                                 if ( status === 204 || s.type === "HEAD" ) {
721                                         statusText = "nocontent";
723                                 // if not modified
724                                 } else if ( status === 304 ) {
725                                         statusText = "notmodified";
727                                 // If we have data, let's convert it
728                                 } else {
729                                         statusText = response.state;
730                                         success = response.data;
731                                         error = response.error;
732                                         isSuccess = !error;
733                                 }
734                         } else {
735                                 // We extract error from statusText
736                                 // then normalize statusText and status 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;