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