Blame view

app/bower_components/jquery/src/ajax.js 21.7 KB
87c93a029   Dang YoungWorld   add modal
1
  define( [
f986e111b   TRUONG   add libs
2
  	"./core",
87c93a029   Dang YoungWorld   add modal
3
4
5
  	"./var/document",
  	"./var/rnothtmlwhite",
  	"./ajax/var/location",
f986e111b   TRUONG   add libs
6
7
  	"./ajax/var/nonce",
  	"./ajax/var/rquery",
87c93a029   Dang YoungWorld   add modal
8

f986e111b   TRUONG   add libs
9
  	"./core/init",
f986e111b   TRUONG   add libs
10
  	"./ajax/parseXML",
87c93a029   Dang YoungWorld   add modal
11
12
13
14
  	"./event/trigger",
  	"./deferred",
  	"./serialize" // jQuery.param
  ], function( jQuery, document, rnothtmlwhite, location, nonce, rquery ) {
f986e111b   TRUONG   add libs
15

87c93a029   Dang YoungWorld   add modal
16
  "use strict";
f986e111b   TRUONG   add libs
17

87c93a029   Dang YoungWorld   add modal
18
19
  var
  	r20 = /%20/g,
f986e111b   TRUONG   add libs
20
  	rhash = /#.*$/,
87c93a029   Dang YoungWorld   add modal
21
22
23
  	rantiCache = /([?&])_=[^&]*/,
  	rheaders = /^(.*?):[ \t]*([^\r
  ]*)$/mg,
f986e111b   TRUONG   add libs
24
25
26
27
  	// #7653, #8125, #8152: local protocol detection
  	rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
  	rnoContent = /^(?:GET|HEAD)$/,
  	rprotocol = /^\/\//,
f986e111b   TRUONG   add libs
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  
  	/* Prefilters
  	 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
  	 * 2) These are called:
  	 *    - BEFORE asking for a transport
  	 *    - AFTER param serialization (s.data is a string if s.processData is true)
  	 * 3) key is the dataType
  	 * 4) the catchall symbol "*" can be used
  	 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
  	 */
  	prefilters = {},
  
  	/* Transports bindings
  	 * 1) key is the dataType
  	 * 2) the catchall symbol "*" can be used
  	 * 3) selection will start with transport dataType and THEN go to "*" if needed
  	 */
  	transports = {},
  
  	// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
87c93a029   Dang YoungWorld   add modal
48
  	allTypes = "*/".concat( "*" ),
f986e111b   TRUONG   add libs
49

87c93a029   Dang YoungWorld   add modal
50
51
52
  	// Anchor tag for parsing the document origin
  	originAnchor = document.createElement( "a" );
  	originAnchor.href = location.href;
f986e111b   TRUONG   add libs
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  
  // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
  function addToPrefiltersOrTransports( structure ) {
  
  	// dataTypeExpression is optional and defaults to "*"
  	return function( dataTypeExpression, func ) {
  
  		if ( typeof dataTypeExpression !== "string" ) {
  			func = dataTypeExpression;
  			dataTypeExpression = "*";
  		}
  
  		var dataType,
  			i = 0,
87c93a029   Dang YoungWorld   add modal
67
  			dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || [];
f986e111b   TRUONG   add libs
68
69
  
  		if ( jQuery.isFunction( func ) ) {
87c93a029   Dang YoungWorld   add modal
70

f986e111b   TRUONG   add libs
71
  			// For each dataType in the dataTypeExpression
87c93a029   Dang YoungWorld   add modal
72
  			while ( ( dataType = dataTypes[ i++ ] ) ) {
f986e111b   TRUONG   add libs
73
  				// Prepend if requested
87c93a029   Dang YoungWorld   add modal
74
  				if ( dataType[ 0 ] === "+" ) {
f986e111b   TRUONG   add libs
75
  					dataType = dataType.slice( 1 ) || "*";
87c93a029   Dang YoungWorld   add modal
76
  					( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
f986e111b   TRUONG   add libs
77
78
79
  
  				// Otherwise append
  				} else {
87c93a029   Dang YoungWorld   add modal
80
  					( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
f986e111b   TRUONG   add libs
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  				}
  			}
  		}
  	};
  }
  
  // Base inspection function for prefilters and transports
  function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
  
  	var inspected = {},
  		seekingTransport = ( structure === transports );
  
  	function inspect( dataType ) {
  		var selected;
  		inspected[ dataType ] = true;
  		jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
  			var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
87c93a029   Dang YoungWorld   add modal
98
99
  			if ( typeof dataTypeOrTransport === "string" &&
  				!seekingTransport && !inspected[ dataTypeOrTransport ] ) {
f986e111b   TRUONG   add libs
100
101
102
103
104
105
  				options.dataTypes.unshift( dataTypeOrTransport );
  				inspect( dataTypeOrTransport );
  				return false;
  			} else if ( seekingTransport ) {
  				return !( selected = dataTypeOrTransport );
  			}
87c93a029   Dang YoungWorld   add modal
106
  		} );
f986e111b   TRUONG   add libs
107
108
109
110
111
112
113
114
115
116
  		return selected;
  	}
  
  	return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
  }
  
  // A special extend for ajax options
  // that takes "flat" options (not to be deep extended)
  // Fixes #9887
  function ajaxExtend( target, src ) {
87c93a029   Dang YoungWorld   add modal
117
  	var key, deep,
f986e111b   TRUONG   add libs
118
119
120
121
  		flatOptions = jQuery.ajaxSettings.flatOptions || {};
  
  	for ( key in src ) {
  		if ( src[ key ] !== undefined ) {
87c93a029   Dang YoungWorld   add modal
122
  			( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
f986e111b   TRUONG   add libs
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  		}
  	}
  	if ( deep ) {
  		jQuery.extend( true, target, deep );
  	}
  
  	return target;
  }
  
  /* Handles responses to an ajax request:
   * - finds the right dataType (mediates between content-type and expected dataType)
   * - returns the corresponding response
   */
  function ajaxHandleResponses( s, jqXHR, responses ) {
87c93a029   Dang YoungWorld   add modal
137
138
  
  	var ct, type, finalDataType, firstDataType,
f986e111b   TRUONG   add libs
139
140
141
142
143
144
145
  		contents = s.contents,
  		dataTypes = s.dataTypes;
  
  	// Remove auto dataType and get content-type in the process
  	while ( dataTypes[ 0 ] === "*" ) {
  		dataTypes.shift();
  		if ( ct === undefined ) {
87c93a029   Dang YoungWorld   add modal
146
  			ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
f986e111b   TRUONG   add libs
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  		}
  	}
  
  	// Check if we're dealing with a known content-type
  	if ( ct ) {
  		for ( type in contents ) {
  			if ( contents[ type ] && contents[ type ].test( ct ) ) {
  				dataTypes.unshift( type );
  				break;
  			}
  		}
  	}
  
  	// Check to see if we have a response for the expected dataType
  	if ( dataTypes[ 0 ] in responses ) {
  		finalDataType = dataTypes[ 0 ];
  	} else {
87c93a029   Dang YoungWorld   add modal
164

f986e111b   TRUONG   add libs
165
166
  		// Try convertible dataTypes
  		for ( type in responses ) {
87c93a029   Dang YoungWorld   add modal
167
  			if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
f986e111b   TRUONG   add libs
168
169
170
171
172
173
174
  				finalDataType = type;
  				break;
  			}
  			if ( !firstDataType ) {
  				firstDataType = type;
  			}
  		}
87c93a029   Dang YoungWorld   add modal
175

f986e111b   TRUONG   add libs
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
  		// Or just use first one
  		finalDataType = finalDataType || firstDataType;
  	}
  
  	// If we found a dataType
  	// We add the dataType to the list if needed
  	// and return the corresponding response
  	if ( finalDataType ) {
  		if ( finalDataType !== dataTypes[ 0 ] ) {
  			dataTypes.unshift( finalDataType );
  		}
  		return responses[ finalDataType ];
  	}
  }
  
  /* Chain conversions given the request and the original response
   * Also sets the responseXXX fields on the jqXHR instance
   */
  function ajaxConvert( s, response, jqXHR, isSuccess ) {
  	var conv2, current, conv, tmp, prev,
  		converters = {},
87c93a029   Dang YoungWorld   add modal
197

f986e111b   TRUONG   add libs
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
  		// Work with a copy of dataTypes in case we need to modify it for conversion
  		dataTypes = s.dataTypes.slice();
  
  	// Create converters map with lowercased keys
  	if ( dataTypes[ 1 ] ) {
  		for ( conv in s.converters ) {
  			converters[ conv.toLowerCase() ] = s.converters[ conv ];
  		}
  	}
  
  	current = dataTypes.shift();
  
  	// Convert to each sequential dataType
  	while ( current ) {
  
  		if ( s.responseFields[ current ] ) {
  			jqXHR[ s.responseFields[ current ] ] = response;
  		}
  
  		// Apply the dataFilter if provided
  		if ( !prev && isSuccess && s.dataFilter ) {
  			response = s.dataFilter( response, s.dataType );
  		}
  
  		prev = current;
  		current = dataTypes.shift();
  
  		if ( current ) {
  
  			// There's only work to do if current dataType is non-auto
  			if ( current === "*" ) {
  
  				current = prev;
  
  			// Convert response if prev dataType is non-auto and differs from current
  			} else if ( prev !== "*" && prev !== current ) {
  
  				// Seek a direct converter
  				conv = converters[ prev + " " + current ] || converters[ "* " + current ];
  
  				// If none found, seek a pair
  				if ( !conv ) {
  					for ( conv2 in converters ) {
  
  						// If conv2 outputs current
  						tmp = conv2.split( " " );
  						if ( tmp[ 1 ] === current ) {
  
  							// If prev can be converted to accepted input
  							conv = converters[ prev + " " + tmp[ 0 ] ] ||
  								converters[ "* " + tmp[ 0 ] ];
  							if ( conv ) {
87c93a029   Dang YoungWorld   add modal
250

f986e111b   TRUONG   add libs
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
  								// Condense equivalence converters
  								if ( conv === true ) {
  									conv = converters[ conv2 ];
  
  								// Otherwise, insert the intermediate dataType
  								} else if ( converters[ conv2 ] !== true ) {
  									current = tmp[ 0 ];
  									dataTypes.unshift( tmp[ 1 ] );
  								}
  								break;
  							}
  						}
  					}
  				}
  
  				// Apply converter (if not an equivalence)
  				if ( conv !== true ) {
  
  					// Unless errors are allowed to bubble, catch and return them
87c93a029   Dang YoungWorld   add modal
270
  					if ( conv && s.throws ) {
f986e111b   TRUONG   add libs
271
272
273
274
275
  						response = conv( response );
  					} else {
  						try {
  							response = conv( response );
  						} catch ( e ) {
87c93a029   Dang YoungWorld   add modal
276
277
278
279
  							return {
  								state: "parsererror",
  								error: conv ? e : "No conversion from " + prev + " to " + current
  							};
f986e111b   TRUONG   add libs
280
281
282
283
284
285
286
287
288
  						}
  					}
  				}
  			}
  		}
  	}
  
  	return { state: "success", data: response };
  }
87c93a029   Dang YoungWorld   add modal
289
  jQuery.extend( {
f986e111b   TRUONG   add libs
290
291
292
293
294
295
296
297
298
  
  	// Counter for holding the number of active queries
  	active: 0,
  
  	// Last-Modified header cache for next request
  	lastModified: {},
  	etag: {},
  
  	ajaxSettings: {
87c93a029   Dang YoungWorld   add modal
299
  		url: location.href,
f986e111b   TRUONG   add libs
300
  		type: "GET",
87c93a029   Dang YoungWorld   add modal
301
  		isLocal: rlocalProtocol.test( location.protocol ),
f986e111b   TRUONG   add libs
302
303
304
305
  		global: true,
  		processData: true,
  		async: true,
  		contentType: "application/x-www-form-urlencoded; charset=UTF-8",
87c93a029   Dang YoungWorld   add modal
306

f986e111b   TRUONG   add libs
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  		/*
  		timeout: 0,
  		data: null,
  		dataType: null,
  		username: null,
  		password: null,
  		cache: null,
  		throws: false,
  		traditional: false,
  		headers: {},
  		*/
  
  		accepts: {
  			"*": allTypes,
  			text: "text/plain",
  			html: "text/html",
  			xml: "application/xml, text/xml",
  			json: "application/json, text/javascript"
  		},
  
  		contents: {
87c93a029   Dang YoungWorld   add modal
328
329
330
  			xml: /\bxml\b/,
  			html: /\bhtml/,
  			json: /\bjson\b/
f986e111b   TRUONG   add libs
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
  		},
  
  		responseFields: {
  			xml: "responseXML",
  			text: "responseText",
  			json: "responseJSON"
  		},
  
  		// Data converters
  		// Keys separate source (or catchall "*") and destination types with a single space
  		converters: {
  
  			// Convert anything to text
  			"* text": String,
  
  			// Text to html (true = no transformation)
  			"text html": true,
  
  			// Evaluate text as a json expression
87c93a029   Dang YoungWorld   add modal
350
  			"text json": JSON.parse,
f986e111b   TRUONG   add libs
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
  
  			// Parse text as xml
  			"text xml": jQuery.parseXML
  		},
  
  		// For options that shouldn't be deep extended:
  		// you can add your own custom options here if
  		// and when you create one that shouldn't be
  		// deep extended (see ajaxExtend)
  		flatOptions: {
  			url: true,
  			context: true
  		}
  	},
  
  	// Creates a full fledged settings object into target
  	// with both ajaxSettings and settings fields.
  	// If target is omitted, writes into ajaxSettings.
  	ajaxSetup: function( target, settings ) {
  		return settings ?
  
  			// Building a settings object
  			ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
  
  			// Extending ajaxSettings
  			ajaxExtend( jQuery.ajaxSettings, target );
  	},
  
  	ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
  	ajaxTransport: addToPrefiltersOrTransports( transports ),
  
  	// Main method
  	ajax: function( url, options ) {
  
  		// If url is an object, simulate pre-1.5 signature
  		if ( typeof url === "object" ) {
  			options = url;
  			url = undefined;
  		}
  
  		// Force options to be an object
  		options = options || {};
87c93a029   Dang YoungWorld   add modal
393
  		var transport,
f986e111b   TRUONG   add libs
394
395
  			// URL without anti-cache param
  			cacheURL,
87c93a029   Dang YoungWorld   add modal
396
397
  
  			// Response headers
f986e111b   TRUONG   add libs
398
  			responseHeadersString,
87c93a029   Dang YoungWorld   add modal
399
  			responseHeaders,
f986e111b   TRUONG   add libs
400
401
  			// timeout handle
  			timeoutTimer,
87c93a029   Dang YoungWorld   add modal
402
403
404
405
406
  			// Url cleanup var
  			urlAnchor,
  
  			// Request state (becomes false upon send and true upon completion)
  			completed,
f986e111b   TRUONG   add libs
407
408
  			// To know if global events are to be dispatched
  			fireGlobals,
87c93a029   Dang YoungWorld   add modal
409
410
411
412
413
  			// Loop variable
  			i,
  
  			// uncached part of the url
  			uncached,
f986e111b   TRUONG   add libs
414
415
  			// Create the final options object
  			s = jQuery.ajaxSetup( {}, options ),
87c93a029   Dang YoungWorld   add modal
416

f986e111b   TRUONG   add libs
417
418
  			// Callbacks context
  			callbackContext = s.context || s,
87c93a029   Dang YoungWorld   add modal
419

f986e111b   TRUONG   add libs
420
  			// Context for global events is callbackContext if it is a DOM node or jQuery collection
87c93a029   Dang YoungWorld   add modal
421
422
423
424
  			globalEventContext = s.context &&
  				( callbackContext.nodeType || callbackContext.jquery ) ?
  					jQuery( callbackContext ) :
  					jQuery.event,
f986e111b   TRUONG   add libs
425
426
  			// Deferreds
  			deferred = jQuery.Deferred(),
87c93a029   Dang YoungWorld   add modal
427
  			completeDeferred = jQuery.Callbacks( "once memory" ),
f986e111b   TRUONG   add libs
428
429
  			// Status-dependent callbacks
  			statusCode = s.statusCode || {},
87c93a029   Dang YoungWorld   add modal
430

f986e111b   TRUONG   add libs
431
432
433
  			// Headers (they are sent all at once)
  			requestHeaders = {},
  			requestHeadersNames = {},
87c93a029   Dang YoungWorld   add modal
434

f986e111b   TRUONG   add libs
435
436
  			// Default abort message
  			strAbort = "canceled",
87c93a029   Dang YoungWorld   add modal
437

f986e111b   TRUONG   add libs
438
439
440
441
442
443
444
  			// Fake xhr
  			jqXHR = {
  				readyState: 0,
  
  				// Builds headers hashtable if needed
  				getResponseHeader: function( key ) {
  					var match;
87c93a029   Dang YoungWorld   add modal
445
  					if ( completed ) {
f986e111b   TRUONG   add libs
446
447
  						if ( !responseHeaders ) {
  							responseHeaders = {};
87c93a029   Dang YoungWorld   add modal
448
449
  							while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
  								responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
f986e111b   TRUONG   add libs
450
451
452
453
454
455
456
457
458
  							}
  						}
  						match = responseHeaders[ key.toLowerCase() ];
  					}
  					return match == null ? null : match;
  				},
  
  				// Raw string
  				getAllResponseHeaders: function() {
87c93a029   Dang YoungWorld   add modal
459
  					return completed ? responseHeadersString : null;
f986e111b   TRUONG   add libs
460
461
462
463
  				},
  
  				// Caches the header
  				setRequestHeader: function( name, value ) {
87c93a029   Dang YoungWorld   add modal
464
465
466
  					if ( completed == null ) {
  						name = requestHeadersNames[ name.toLowerCase() ] =
  							requestHeadersNames[ name.toLowerCase() ] || name;
f986e111b   TRUONG   add libs
467
468
469
470
471
472
473
  						requestHeaders[ name ] = value;
  					}
  					return this;
  				},
  
  				// Overrides response content-type header
  				overrideMimeType: function( type ) {
87c93a029   Dang YoungWorld   add modal
474
  					if ( completed == null ) {
f986e111b   TRUONG   add libs
475
476
477
478
479
480
481
482
483
  						s.mimeType = type;
  					}
  					return this;
  				},
  
  				// Status-dependent callbacks
  				statusCode: function( map ) {
  					var code;
  					if ( map ) {
87c93a029   Dang YoungWorld   add modal
484
485
486
487
488
489
490
  						if ( completed ) {
  
  							// Execute the appropriate callbacks
  							jqXHR.always( map[ jqXHR.status ] );
  						} else {
  
  							// Lazy-add the new callbacks in a way that preserves old ones
f986e111b   TRUONG   add libs
491
  							for ( code in map ) {
f986e111b   TRUONG   add libs
492
493
  								statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
  							}
f986e111b   TRUONG   add libs
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
  						}
  					}
  					return this;
  				},
  
  				// Cancel the request
  				abort: function( statusText ) {
  					var finalText = statusText || strAbort;
  					if ( transport ) {
  						transport.abort( finalText );
  					}
  					done( 0, finalText );
  					return this;
  				}
  			};
  
  		// Attach deferreds
87c93a029   Dang YoungWorld   add modal
511
  		deferred.promise( jqXHR );
f986e111b   TRUONG   add libs
512

87c93a029   Dang YoungWorld   add modal
513
  		// Add protocol if not provided (prefilters might expect it)
f986e111b   TRUONG   add libs
514
515
  		// Handle falsy url in the settings object (#10093: consistency with old signature)
  		// We also use the url parameter if available
87c93a029   Dang YoungWorld   add modal
516
517
  		s.url = ( ( url || s.url || location.href ) + "" )
  			.replace( rprotocol, location.protocol + "//" );
f986e111b   TRUONG   add libs
518
519
520
521
522
  
  		// Alias method option to type as per ticket #12004
  		s.type = options.method || options.type || s.method || s.type;
  
  		// Extract dataTypes list
87c93a029   Dang YoungWorld   add modal
523
  		s.dataTypes = ( s.dataType || "*" ).toLowerCase().match( rnothtmlwhite ) || [ "" ];
f986e111b   TRUONG   add libs
524

87c93a029   Dang YoungWorld   add modal
525
  		// A cross-domain request is in order when the origin doesn't match the current origin.
f986e111b   TRUONG   add libs
526
  		if ( s.crossDomain == null ) {
87c93a029   Dang YoungWorld   add modal
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
  			urlAnchor = document.createElement( "a" );
  
  			// Support: IE <=8 - 11, Edge 12 - 13
  			// IE throws exception on accessing the href property if url is malformed,
  			// e.g. http://example.com:80x/
  			try {
  				urlAnchor.href = s.url;
  
  				// Support: IE <=8 - 11 only
  				// Anchor's host property isn't correctly set when s.url is relative
  				urlAnchor.href = urlAnchor.href;
  				s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
  					urlAnchor.protocol + "//" + urlAnchor.host;
  			} catch ( e ) {
  
  				// If there is an error parsing the URL, assume it is crossDomain,
  				// it can be rejected by the transport if it is invalid
  				s.crossDomain = true;
  			}
f986e111b   TRUONG   add libs
546
547
548
549
550
551
552
553
554
555
556
  		}
  
  		// Convert data if not already a string
  		if ( s.data && s.processData && typeof s.data !== "string" ) {
  			s.data = jQuery.param( s.data, s.traditional );
  		}
  
  		// Apply prefilters
  		inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
  
  		// If request was aborted inside a prefilter, stop there
87c93a029   Dang YoungWorld   add modal
557
  		if ( completed ) {
f986e111b   TRUONG   add libs
558
559
560
561
562
563
564
565
566
  			return jqXHR;
  		}
  
  		// We can fire global events as of now if asked to
  		// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
  		fireGlobals = jQuery.event && s.global;
  
  		// Watch for a new set of requests
  		if ( fireGlobals && jQuery.active++ === 0 ) {
87c93a029   Dang YoungWorld   add modal
567
  			jQuery.event.trigger( "ajaxStart" );
f986e111b   TRUONG   add libs
568
569
570
571
572
573
574
575
576
577
  		}
  
  		// Uppercase the type
  		s.type = s.type.toUpperCase();
  
  		// Determine if request has content
  		s.hasContent = !rnoContent.test( s.type );
  
  		// Save the URL in case we're toying with the If-Modified-Since
  		// and/or If-None-Match header later on
87c93a029   Dang YoungWorld   add modal
578
579
  		// Remove hash to simplify url manipulation
  		cacheURL = s.url.replace( rhash, "" );
f986e111b   TRUONG   add libs
580
581
582
  
  		// More options handling for requests with no content
  		if ( !s.hasContent ) {
87c93a029   Dang YoungWorld   add modal
583
584
  			// Remember the hash so we can put it back
  			uncached = s.url.slice( cacheURL.length );
f986e111b   TRUONG   add libs
585
586
  			// If data is available, append data to url
  			if ( s.data ) {
87c93a029   Dang YoungWorld   add modal
587
  				cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data;
f986e111b   TRUONG   add libs
588
589
590
  				// #9682: remove data so that it's not used in an eventual retry
  				delete s.data;
  			}
87c93a029   Dang YoungWorld   add modal
591
  			// Add or update anti-cache param if needed
f986e111b   TRUONG   add libs
592
  			if ( s.cache === false ) {
87c93a029   Dang YoungWorld   add modal
593
594
595
  				cacheURL = cacheURL.replace( rantiCache, "$1" );
  				uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
  			}
f986e111b   TRUONG   add libs
596

87c93a029   Dang YoungWorld   add modal
597
598
  			// Put hash and anti-cache on the URL that will be requested (gh-1732)
  			s.url = cacheURL + uncached;
f986e111b   TRUONG   add libs
599

87c93a029   Dang YoungWorld   add modal
600
601
602
603
  		// Change '%20' to '+' if this is encoded form body content (gh-2658)
  		} else if ( s.data && s.processData &&
  			( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) === 0 ) {
  			s.data = s.data.replace( r20, "+" );
f986e111b   TRUONG   add libs
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
  		}
  
  		// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  		if ( s.ifModified ) {
  			if ( jQuery.lastModified[ cacheURL ] ) {
  				jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
  			}
  			if ( jQuery.etag[ cacheURL ] ) {
  				jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
  			}
  		}
  
  		// Set the correct header, if data is being sent
  		if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
  			jqXHR.setRequestHeader( "Content-Type", s.contentType );
  		}
  
  		// Set the Accepts header for the server, depending on the dataType
  		jqXHR.setRequestHeader(
  			"Accept",
87c93a029   Dang YoungWorld   add modal
624
625
626
  			s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
  				s.accepts[ s.dataTypes[ 0 ] ] +
  					( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
f986e111b   TRUONG   add libs
627
628
629
630
631
632
633
634
635
  				s.accepts[ "*" ]
  		);
  
  		// Check for headers option
  		for ( i in s.headers ) {
  			jqXHR.setRequestHeader( i, s.headers[ i ] );
  		}
  
  		// Allow custom headers/mimetypes and early abort
87c93a029   Dang YoungWorld   add modal
636
637
  		if ( s.beforeSend &&
  			( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) {
f986e111b   TRUONG   add libs
638
639
640
  			// Abort if not done already and return
  			return jqXHR.abort();
  		}
87c93a029   Dang YoungWorld   add modal
641
  		// Aborting is no longer a cancellation
f986e111b   TRUONG   add libs
642
643
644
  		strAbort = "abort";
  
  		// Install callbacks on deferreds
87c93a029   Dang YoungWorld   add modal
645
646
647
  		completeDeferred.add( s.complete );
  		jqXHR.done( s.success );
  		jqXHR.fail( s.error );
f986e111b   TRUONG   add libs
648
649
650
651
652
653
654
655
656
657
658
659
660
661
  
  		// Get transport
  		transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
  
  		// If no transport, we auto-abort
  		if ( !transport ) {
  			done( -1, "No Transport" );
  		} else {
  			jqXHR.readyState = 1;
  
  			// Send global event
  			if ( fireGlobals ) {
  				globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
  			}
87c93a029   Dang YoungWorld   add modal
662
663
664
665
666
  
  			// If request was aborted inside ajaxSend, stop there
  			if ( completed ) {
  				return jqXHR;
  			}
f986e111b   TRUONG   add libs
667
668
  			// Timeout
  			if ( s.async && s.timeout > 0 ) {
87c93a029   Dang YoungWorld   add modal
669
670
  				timeoutTimer = window.setTimeout( function() {
  					jqXHR.abort( "timeout" );
f986e111b   TRUONG   add libs
671
672
673
674
  				}, s.timeout );
  			}
  
  			try {
87c93a029   Dang YoungWorld   add modal
675
  				completed = false;
f986e111b   TRUONG   add libs
676
677
  				transport.send( requestHeaders, done );
  			} catch ( e ) {
87c93a029   Dang YoungWorld   add modal
678
679
680
  
  				// Rethrow post-completion exceptions
  				if ( completed ) {
f986e111b   TRUONG   add libs
681
682
  					throw e;
  				}
87c93a029   Dang YoungWorld   add modal
683
684
685
  
  				// Propagate others as results
  				done( -1, e );
f986e111b   TRUONG   add libs
686
687
688
689
690
691
692
  			}
  		}
  
  		// Callback for when everything is done
  		function done( status, nativeStatusText, responses, headers ) {
  			var isSuccess, success, error, response, modified,
  				statusText = nativeStatusText;
87c93a029   Dang YoungWorld   add modal
693
694
  			// Ignore repeat invocations
  			if ( completed ) {
f986e111b   TRUONG   add libs
695
696
  				return;
  			}
87c93a029   Dang YoungWorld   add modal
697
  			completed = true;
f986e111b   TRUONG   add libs
698
699
700
  
  			// Clear timeout if it exists
  			if ( timeoutTimer ) {
87c93a029   Dang YoungWorld   add modal
701
  				window.clearTimeout( timeoutTimer );
f986e111b   TRUONG   add libs
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
  			}
  
  			// Dereference transport for early garbage collection
  			// (no matter how long the jqXHR object will be used)
  			transport = undefined;
  
  			// Cache response headers
  			responseHeadersString = headers || "";
  
  			// Set readyState
  			jqXHR.readyState = status > 0 ? 4 : 0;
  
  			// Determine if successful
  			isSuccess = status >= 200 && status < 300 || status === 304;
  
  			// Get response data
  			if ( responses ) {
  				response = ajaxHandleResponses( s, jqXHR, responses );
  			}
  
  			// Convert no matter what (that way responseXXX fields are always set)
  			response = ajaxConvert( s, response, jqXHR, isSuccess );
  
  			// If successful, handle type chaining
  			if ( isSuccess ) {
  
  				// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
  				if ( s.ifModified ) {
87c93a029   Dang YoungWorld   add modal
730
  					modified = jqXHR.getResponseHeader( "Last-Modified" );
f986e111b   TRUONG   add libs
731
732
733
  					if ( modified ) {
  						jQuery.lastModified[ cacheURL ] = modified;
  					}
87c93a029   Dang YoungWorld   add modal
734
  					modified = jqXHR.getResponseHeader( "etag" );
f986e111b   TRUONG   add libs
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
  					if ( modified ) {
  						jQuery.etag[ cacheURL ] = modified;
  					}
  				}
  
  				// if no content
  				if ( status === 204 || s.type === "HEAD" ) {
  					statusText = "nocontent";
  
  				// if not modified
  				} else if ( status === 304 ) {
  					statusText = "notmodified";
  
  				// If we have data, let's convert it
  				} else {
  					statusText = response.state;
  					success = response.data;
  					error = response.error;
  					isSuccess = !error;
  				}
  			} else {
87c93a029   Dang YoungWorld   add modal
756
757
  
  				// Extract error from statusText and normalize for non-aborts
f986e111b   TRUONG   add libs
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
  				error = statusText;
  				if ( status || !statusText ) {
  					statusText = "error";
  					if ( status < 0 ) {
  						status = 0;
  					}
  				}
  			}
  
  			// Set data for the fake xhr object
  			jqXHR.status = status;
  			jqXHR.statusText = ( nativeStatusText || statusText ) + "";
  
  			// Success/Error
  			if ( isSuccess ) {
  				deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
  			} else {
  				deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
  			}
  
  			// Status-dependent callbacks
  			jqXHR.statusCode( statusCode );
  			statusCode = undefined;
  
  			if ( fireGlobals ) {
  				globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
  					[ jqXHR, s, isSuccess ? success : error ] );
  			}
  
  			// Complete
  			completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
  
  			if ( fireGlobals ) {
  				globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
87c93a029   Dang YoungWorld   add modal
792

f986e111b   TRUONG   add libs
793
794
  				// Handle the global AJAX counter
  				if ( !( --jQuery.active ) ) {
87c93a029   Dang YoungWorld   add modal
795
  					jQuery.event.trigger( "ajaxStop" );
f986e111b   TRUONG   add libs
796
797
798
799
800
801
802
803
804
805
806
807
808
809
  				}
  			}
  		}
  
  		return jqXHR;
  	},
  
  	getJSON: function( url, data, callback ) {
  		return jQuery.get( url, data, callback, "json" );
  	},
  
  	getScript: function( url, callback ) {
  		return jQuery.get( url, undefined, callback, "script" );
  	}
87c93a029   Dang YoungWorld   add modal
810
  } );
f986e111b   TRUONG   add libs
811
812
813
  
  jQuery.each( [ "get", "post" ], function( i, method ) {
  	jQuery[ method ] = function( url, data, callback, type ) {
87c93a029   Dang YoungWorld   add modal
814
815
  
  		// Shift arguments if data argument was omitted
f986e111b   TRUONG   add libs
816
817
818
819
820
  		if ( jQuery.isFunction( data ) ) {
  			type = type || callback;
  			callback = data;
  			data = undefined;
  		}
87c93a029   Dang YoungWorld   add modal
821
822
  		// The url can be an options object (which then must have .url)
  		return jQuery.ajax( jQuery.extend( {
f986e111b   TRUONG   add libs
823
824
825
826
827
  			url: url,
  			type: method,
  			dataType: type,
  			data: data,
  			success: callback
87c93a029   Dang YoungWorld   add modal
828
  		}, jQuery.isPlainObject( url ) && url ) );
f986e111b   TRUONG   add libs
829
  	};
87c93a029   Dang YoungWorld   add modal
830
  } );
f986e111b   TRUONG   add libs
831
832
  
  return jQuery;
87c93a029   Dang YoungWorld   add modal
833
  } );