scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 58 Rev 125
Line 1... Line 1...
1 define( [ 1 define([
2 "./core", 2 "./core",
3 "./var/document", -  
4 "./var/rnothtmlwhite", 3 "./var/rnotwhite",
5 "./ajax/var/location", -  
6 "./ajax/var/nonce", 4 "./ajax/var/nonce",
7 "./ajax/var/rquery", 5 "./ajax/var/rquery",
8   -  
9 "./core/init", 6 "./core/init",
-   7 "./ajax/parseJSON",
10 "./ajax/parseXML", 8 "./ajax/parseXML",
11 "./event/trigger", -  
12 "./deferred", 9 "./deferred"
13 "./serialize" // jQuery.param -  
14 ], function( jQuery, document, rnothtmlwhite, location, nonce, rquery ) { 10 ], function( jQuery, rnotwhite, nonce, rquery ) {
15   -  
16 "use strict"; -  
Line 17... Line 11...
17   11  
18 var -  
19 r20 = /%20/g, 12 var
20 rhash = /#.*$/, 13 rhash = /#.*$/,
21 rantiCache = /([?&])_=[^&]*/, 14 rts = /([?&])_=[^&]*/,
22 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg, -  
23   15 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
24 // #7653, #8125, #8152: local protocol detection 16 // #7653, #8125, #8152: local protocol detection
25 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/, 17 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
26 rnoContent = /^(?:GET|HEAD)$/, 18 rnoContent = /^(?:GET|HEAD)$/,
-   19 rprotocol = /^\/\//,
Line 27... Line 20...
27 rprotocol = /^\/\//, 20 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
28   21  
29 /* Prefilters 22 /* Prefilters
30 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example) 23 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
Line 45... Line 38...
45 transports = {}, 38 transports = {},
Line 46... Line 39...
46   39  
47 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression 40 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
Line -... Line 41...
-   41 allTypes = "*/".concat( "*" ),
48 allTypes = "*/".concat( "*" ), 42  
-   43 // Document location
49   44 ajaxLocation = window.location.href,
50 // Anchor tag for parsing the document origin 45  
Line 51... Line 46...
51 originAnchor = document.createElement( "a" ); 46 // Segment location into parts
52 originAnchor.href = location.href; 47 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
Line 53... Line 48...
53   48  
Line 62... Line 57...
62 dataTypeExpression = "*"; 57 dataTypeExpression = "*";
63 } 58 }
Line 64... Line 59...
64   59  
65 var dataType, 60 var dataType,
66 i = 0, 61 i = 0,
Line 67... Line 62...
67 dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || []; 62 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
68   -  
69 if ( jQuery.isFunction( func ) ) { 63  
70   64 if ( jQuery.isFunction( func ) ) {
71 // For each dataType in the dataTypeExpression -  
72 while ( ( dataType = dataTypes[ i++ ] ) ) { 65 // For each dataType in the dataTypeExpression
73   66 while ( (dataType = dataTypes[i++]) ) {
74 // Prepend if requested 67 // Prepend if requested
75 if ( dataType[ 0 ] === "+" ) { 68 if ( dataType[0] === "+" ) {
Line 76... Line 69...
76 dataType = dataType.slice( 1 ) || "*"; 69 dataType = dataType.slice( 1 ) || "*";
77 ( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func ); 70 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
78   71  
79 // Otherwise append 72 // Otherwise append
80 } else { 73 } else {
81 ( structure[ dataType ] = structure[ dataType ] || [] ).push( func ); 74 (structure[ dataType ] = structure[ dataType ] || []).push( func );
82 } 75 }
83 } 76 }
Line 94... Line 87...
94 function inspect( dataType ) { 87 function inspect( dataType ) {
95 var selected; 88 var selected;
96 inspected[ dataType ] = true; 89 inspected[ dataType ] = true;
97 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) { 90 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
98 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR ); 91 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
99 if ( typeof dataTypeOrTransport === "string" && -  
100 !seekingTransport && !inspected[ dataTypeOrTransport ] ) { 92 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
101   -  
102 options.dataTypes.unshift( dataTypeOrTransport ); 93 options.dataTypes.unshift( dataTypeOrTransport );
103 inspect( dataTypeOrTransport ); 94 inspect( dataTypeOrTransport );
104 return false; 95 return false;
105 } else if ( seekingTransport ) { 96 } else if ( seekingTransport ) {
106 return !( selected = dataTypeOrTransport ); 97 return !( selected = dataTypeOrTransport );
107 } 98 }
108 } ); 99 });
109 return selected; 100 return selected;
110 } 101 }
Line 111... Line 102...
111   102  
112 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" ); 103 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
Line 119... Line 110...
119 var key, deep, 110 var key, deep,
120 flatOptions = jQuery.ajaxSettings.flatOptions || {}; 111 flatOptions = jQuery.ajaxSettings.flatOptions || {};
Line 121... Line 112...
121   112  
122 for ( key in src ) { 113 for ( key in src ) {
123 if ( src[ key ] !== undefined ) { 114 if ( src[ key ] !== undefined ) {
124 ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ]; 115 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
125 } 116 }
126 } 117 }
127 if ( deep ) { 118 if ( deep ) {
128 jQuery.extend( true, target, deep ); 119 jQuery.extend( true, target, deep );
Line 143... Line 134...
143   134  
144 // Remove auto dataType and get content-type in the process 135 // Remove auto dataType and get content-type in the process
145 while ( dataTypes[ 0 ] === "*" ) { 136 while ( dataTypes[ 0 ] === "*" ) {
146 dataTypes.shift(); 137 dataTypes.shift();
147 if ( ct === undefined ) { 138 if ( ct === undefined ) {
148 ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" ); 139 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
149 } 140 }
Line 150... Line 141...
150 } 141 }
151   142  
Line 161... Line 152...
161   152  
162 // Check to see if we have a response for the expected dataType 153 // Check to see if we have a response for the expected dataType
163 if ( dataTypes[ 0 ] in responses ) { 154 if ( dataTypes[ 0 ] in responses ) {
164 finalDataType = dataTypes[ 0 ]; 155 finalDataType = dataTypes[ 0 ];
165 } else { -  
166   156 } else {
167 // Try convertible dataTypes 157 // Try convertible dataTypes
168 for ( type in responses ) { 158 for ( type in responses ) {
169 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) { 159 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
170 finalDataType = type; 160 finalDataType = type;
171 break; 161 break;
172 } 162 }
173 if ( !firstDataType ) { 163 if ( !firstDataType ) {
174 firstDataType = type; 164 firstDataType = type;
175 } 165 }
176 } -  
177   166 }
178 // Or just use first one 167 // Or just use first one
179 finalDataType = finalDataType || firstDataType; 168 finalDataType = finalDataType || firstDataType;
Line 180... Line 169...
180 } 169 }
Line 194... Line 183...
194 * Also sets the responseXXX fields on the jqXHR instance 183 * Also sets the responseXXX fields on the jqXHR instance
195 */ 184 */
196 function ajaxConvert( s, response, jqXHR, isSuccess ) { 185 function ajaxConvert( s, response, jqXHR, isSuccess ) {
197 var conv2, current, conv, tmp, prev, 186 var conv2, current, conv, tmp, prev,
198 converters = {}, 187 converters = {},
199   -  
200 // Work with a copy of dataTypes in case we need to modify it for conversion 188 // Work with a copy of dataTypes in case we need to modify it for conversion
201 dataTypes = s.dataTypes.slice(); 189 dataTypes = s.dataTypes.slice();
Line 202... Line 190...
202   190  
203 // Create converters map with lowercased keys 191 // Create converters map with lowercased keys
Line 224... Line 212...
224 prev = current; 212 prev = current;
225 current = dataTypes.shift(); 213 current = dataTypes.shift();
Line 226... Line 214...
226   214  
Line 227... Line 215...
227 if ( current ) { 215 if ( current ) {
228   216  
Line 229... Line 217...
229 // There's only work to do if current dataType is non-auto 217 // There's only work to do if current dataType is non-auto
Line 230... Line 218...
230 if ( current === "*" ) { 218 if ( current === "*" ) {
Line 247... Line 235...
247   235  
248 // If prev can be converted to accepted input 236 // If prev can be converted to accepted input
249 conv = converters[ prev + " " + tmp[ 0 ] ] || 237 conv = converters[ prev + " " + tmp[ 0 ] ] ||
250 converters[ "* " + tmp[ 0 ] ]; 238 converters[ "* " + tmp[ 0 ] ];
251 if ( conv ) { -  
252   239 if ( conv ) {
253 // Condense equivalence converters 240 // Condense equivalence converters
254 if ( conv === true ) { 241 if ( conv === true ) {
Line 255... Line 242...
255 conv = converters[ conv2 ]; 242 conv = converters[ conv2 ];
Line 267... Line 254...
267   254  
268 // Apply converter (if not an equivalence) 255 // Apply converter (if not an equivalence)
Line 269... Line 256...
269 if ( conv !== true ) { 256 if ( conv !== true ) {
270   257  
271 // Unless errors are allowed to bubble, catch and return them 258 // Unless errors are allowed to bubble, catch and return them
272 if ( conv && s.throws ) { 259 if ( conv && s[ "throws" ] ) {
273 response = conv( response ); 260 response = conv( response );
274 } else { 261 } else {
275 try { 262 try {
276 response = conv( response ); -  
277 } catch ( e ) { -  
278 return { 263 response = conv( response );
279 state: "parsererror", -  
280 error: conv ? e : "No conversion from " + prev + " to " + current 264 } catch ( e ) {
281 }; 265 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
282 } 266 }
283 } 267 }
284 } 268 }
285 } 269 }
Line 286... Line 270...
286 } 270 }
287 } 271 }
Line 288... Line 272...
288   272  
Line 289... Line 273...
289 return { state: "success", data: response }; 273 return { state: "success", data: response };
290 } 274 }
Line 291... Line 275...
291   275  
292 jQuery.extend( { 276 jQuery.extend({
293   277  
Line 294... Line 278...
294 // Counter for holding the number of active queries 278 // Counter for holding the number of active queries
295 active: 0, 279 active: 0,
296   280  
297 // Last-Modified header cache for next request 281 // Last-Modified header cache for next request
298 lastModified: {}, 282 lastModified: {},
299 etag: {}, 283 etag: {},
300   284  
301 ajaxSettings: { 285 ajaxSettings: {
302 url: location.href, -  
303 type: "GET", 286 url: ajaxLocation,
304 isLocal: rlocalProtocol.test( location.protocol ), 287 type: "GET",
305 global: true, 288 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
306 processData: true, 289 global: true,
307 async: true, 290 processData: true,
Line 326... Line 309...
326 xml: "application/xml, text/xml", 309 xml: "application/xml, text/xml",
327 json: "application/json, text/javascript" 310 json: "application/json, text/javascript"
328 }, 311 },
Line 329... Line 312...
329   312  
330 contents: { 313 contents: {
331 xml: /\bxml\b/, 314 xml: /xml/,
332 html: /\bhtml/, 315 html: /html/,
333 json: /\bjson\b/ 316 json: /json/
Line 334... Line 317...
334 }, 317 },
335   318  
336 responseFields: { 319 responseFields: {
Line 348... Line 331...
348   331  
349 // Text to html (true = no transformation) 332 // Text to html (true = no transformation)
Line 350... Line 333...
350 "text html": true, 333 "text html": true,
351   334  
Line 352... Line 335...
352 // Evaluate text as a json expression 335 // Evaluate text as a json expression
353 "text json": JSON.parse, 336 "text json": jQuery.parseJSON,
354   337  
Line 393... Line 376...
393   376  
394 // Force options to be an object 377 // Force options to be an object
Line 395... Line 378...
395 options = options || {}; 378 options = options || {};
396   -  
397 var transport, 379  
398   380 var transport,
399 // URL without anti-cache param -  
400 cacheURL, 381 // URL without anti-cache param
401   382 cacheURL,
402 // Response headers 383 // Response headers
403 responseHeadersString, -  
404 responseHeaders, 384 responseHeadersString,
405   385 responseHeaders,
406 // timeout handle -  
407 timeoutTimer, 386 // timeout handle
408   -  
409 // Url cleanup var -  
410 urlAnchor, -  
411   387 timeoutTimer,
412 // Request state (becomes false upon send and true upon completion) -  
413 completed, 388 // Cross-domain detection vars
414   389 parts,
415 // To know if global events are to be dispatched -  
416 fireGlobals, 390 // To know if global events are to be dispatched
417   391 fireGlobals,
418 // Loop variable -  
419 i, -  
420   -  
421 // uncached part of the url -  
422 uncached, 392 // Loop variable
423   393 i,
424 // Create the final options object -  
425 s = jQuery.ajaxSetup( {}, options ), 394 // Create the final options object
426   395 s = jQuery.ajaxSetup( {}, options ),
427 // Callbacks context -  
428 callbackContext = s.context || s, 396 // Callbacks context
429   -  
430 // Context for global events is callbackContext if it is a DOM node or jQuery collection 397 callbackContext = s.context || s,
431 globalEventContext = s.context && 398 // Context for global events is callbackContext if it is a DOM node or jQuery collection
432 ( callbackContext.nodeType || callbackContext.jquery ) ? 399 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
433 jQuery( callbackContext ) : -  
434 jQuery.event, 400 jQuery( callbackContext ) :
435   401 jQuery.event,
436 // Deferreds 402 // Deferreds
437 deferred = jQuery.Deferred(), -  
438 completeDeferred = jQuery.Callbacks( "once memory" ), 403 deferred = jQuery.Deferred(),
439   404 completeDeferred = jQuery.Callbacks("once memory"),
440 // Status-dependent callbacks -  
441 statusCode = s.statusCode || {}, 405 // Status-dependent callbacks
442   406 statusCode = s.statusCode || {},
443 // Headers (they are sent all at once) 407 // Headers (they are sent all at once)
-   408 requestHeaders = {},
444 requestHeaders = {}, 409 requestHeadersNames = {},
445 requestHeadersNames = {}, 410 // The jqXHR state
446   411 state = 0,
447 // Default abort message -  
448 strAbort = "canceled", 412 // Default abort message
449   413 strAbort = "canceled",
450 // Fake xhr 414 // Fake xhr
Line 451... Line 415...
451 jqXHR = { 415 jqXHR = {
452 readyState: 0, 416 readyState: 0,
453   417  
454 // Builds headers hashtable if needed 418 // Builds headers hashtable if needed
455 getResponseHeader: function( key ) { 419 getResponseHeader: function( key ) {
456 var match; 420 var match;
457 if ( completed ) { 421 if ( state === 2 ) {
458 if ( !responseHeaders ) { 422 if ( !responseHeaders ) {
459 responseHeaders = {}; 423 responseHeaders = {};
460 while ( ( match = rheaders.exec( responseHeadersString ) ) ) { 424 while ( (match = rheaders.exec( responseHeadersString )) ) {
461 responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ]; 425 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
462 } 426 }
463 } 427 }
464 match = responseHeaders[ key.toLowerCase() ]; 428 match = responseHeaders[ key.toLowerCase() ];
Line 465... Line 429...
465 } 429 }
466 return match == null ? null : match; 430 return match == null ? null : match;
467 }, 431 },
468   432  
Line 469... Line 433...
469 // Raw string 433 // Raw string
470 getAllResponseHeaders: function() { 434 getAllResponseHeaders: function() {
471 return completed ? responseHeadersString : null; 435 return state === 2 ? responseHeadersString : null;
472 }, 436 },
473   437  
474 // Caches the header 438 // Caches the header
475 setRequestHeader: function( name, value ) { 439 setRequestHeader: function( name, value ) {
476 if ( completed == null ) { 440 var lname = name.toLowerCase();
477 name = requestHeadersNames[ name.toLowerCase() ] = 441 if ( !state ) {
Line 478... Line 442...
478 requestHeadersNames[ name.toLowerCase() ] || name; 442 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
479 requestHeaders[ name ] = value; 443 requestHeaders[ name ] = value;
480 } 444 }
481 return this; 445 return this;
482 }, 446 },
483   447  
484 // Overrides response content-type header 448 // Overrides response content-type header
Line 485... Line 449...
485 overrideMimeType: function( type ) { 449 overrideMimeType: function( type ) {
486 if ( completed == null ) { 450 if ( !state ) {
487 s.mimeType = type; 451 s.mimeType = type;
488 } 452 }
489 return this; 453 return this;
490 }, -  
491   -  
492 // Status-dependent callbacks -  
493 statusCode: function( map ) { -  
494 var code; -  
495 if ( map ) { -  
496 if ( completed ) { 454 },
-   455  
497   456 // Status-dependent callbacks
498 // Execute the appropriate callbacks 457 statusCode: function( map ) {
-   458 var code;
-   459 if ( map ) {
-   460 if ( state < 2 ) {
499 jqXHR.always( map[ jqXHR.status ] ); 461 for ( code in map ) {
500 } else { 462 // Lazy-add the new callback in a way that preserves old ones
501   463 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
502 // Lazy-add the new callbacks in a way that preserves old ones 464 }
Line 518... Line 480...
518 return this; 480 return this;
519 } 481 }
520 }; 482 };
Line 521... Line 483...
521   483  
-   484 // Attach deferreds
-   485 deferred.promise( jqXHR ).complete = completeDeferred.add;
522 // Attach deferreds 486 jqXHR.success = jqXHR.done;
Line -... Line 487...
-   487 jqXHR.error = jqXHR.fail;
523 deferred.promise( jqXHR ); 488  
524   489 // Remove hash character (#7531: and string promotion)
525 // Add protocol if not provided (prefilters might expect it) 490 // Add protocol if not provided (prefilters might expect it)
526 // Handle falsy url in the settings object (#10093: consistency with old signature) 491 // Handle falsy url in the settings object (#10093: consistency with old signature)
527 // We also use the url parameter if available 492 // We also use the url parameter if available
Line 528... Line 493...
528 s.url = ( ( url || s.url || location.href ) + "" ) 493 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
529 .replace( rprotocol, location.protocol + "//" ); 494 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
Line 530... Line 495...
530   495  
531 // Alias method option to type as per ticket #12004 496 // Alias method option to type as per ticket #12004
Line 532... Line 497...
532 s.type = options.method || options.type || s.method || s.type; 497 s.type = options.method || options.type || s.method || s.type;
533   498  
534 // Extract dataTypes list 499 // Extract dataTypes list
535 s.dataTypes = ( s.dataType || "*" ).toLowerCase().match( rnothtmlwhite ) || [ "" ]; -  
536   -  
537 // A cross-domain request is in order when the origin doesn't match the current origin. -  
538 if ( s.crossDomain == null ) { -  
539 urlAnchor = document.createElement( "a" ); -  
540   -  
541 // Support: IE <=8 - 11, Edge 12 - 13 -  
542 // IE throws exception on accessing the href property if url is malformed, 500 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
543 // e.g. http://example.com:80x/ 501  
544 try { -  
545 urlAnchor.href = s.url; 502 // A cross-domain request is in order when we have a protocol:host:port mismatch
546   -  
547 // Support: IE <=8 - 11 only -  
548 // Anchor's host property isn't correctly set when s.url is relative -  
549 urlAnchor.href = urlAnchor.href; 503 if ( s.crossDomain == null ) {
550 s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !== -  
551 urlAnchor.protocol + "//" + urlAnchor.host; -  
552 } catch ( e ) { 504 parts = rurl.exec( s.url.toLowerCase() );
553   505 s.crossDomain = !!( parts &&
Line 554... Line 506...
554 // If there is an error parsing the URL, assume it is crossDomain, 506 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
555 // it can be rejected by the transport if it is invalid 507 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
556 s.crossDomain = true; 508 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
Line 564... Line 516...
564   516  
565 // Apply prefilters 517 // Apply prefilters
Line 566... Line 518...
566 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR ); 518 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
567   519  
568 // If request was aborted inside a prefilter, stop there 520 // If request was aborted inside a prefilter, stop there
569 if ( completed ) { 521 if ( state === 2 ) {
Line 570... Line 522...
570 return jqXHR; 522 return jqXHR;
571 } 523 }
572   524  
Line 573... Line 525...
573 // We can fire global events as of now if asked to 525 // We can fire global events as of now if asked to
574 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118) 526 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
575 fireGlobals = jQuery.event && s.global; 527 fireGlobals = jQuery.event && s.global;
576   528  
Line 577... Line 529...
577 // Watch for a new set of requests 529 // Watch for a new set of requests
578 if ( fireGlobals && jQuery.active++ === 0 ) { 530 if ( fireGlobals && jQuery.active++ === 0 ) {
Line 579... Line 531...
579 jQuery.event.trigger( "ajaxStart" ); 531 jQuery.event.trigger("ajaxStart");
580 } 532 }
Line 581... Line 533...
581   533  
582 // Uppercase the type 534 // Uppercase the type
583 s.type = s.type.toUpperCase(); -  
584   535 s.type = s.type.toUpperCase();
Line 585... Line 536...
585 // Determine if request has content 536  
586 s.hasContent = !rnoContent.test( s.type ); 537 // Determine if request has content
Line 587... Line -...
587   -  
588 // Save the URL in case we're toying with the If-Modified-Since -  
589 // and/or If-None-Match header later on -  
590 // Remove hash to simplify url manipulation 538 s.hasContent = !rnoContent.test( s.type );
591 cacheURL = s.url.replace( rhash, "" ); 539  
592   540 // Save the URL in case we're toying with the If-Modified-Since
593 // More options handling for requests with no content -  
594 if ( !s.hasContent ) { 541 // and/or If-None-Match header later on
595   542 cacheURL = s.url;
596 // Remember the hash so we can put it back 543  
Line 597... Line 544...
597 uncached = s.url.slice( cacheURL.length ); 544 // More options handling for requests with no content
598   545 if ( !s.hasContent ) {
599 // If data is available, append data to url 546  
600 if ( s.data ) { -  
601 cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data; -  
Line 602... Line 547...
602   547 // If data is available, append data to url
603 // #9682: remove data so that it's not used in an eventual retry 548 if ( s.data ) {
Line 604... Line -...
604 delete s.data; -  
605 } 549 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
606   550 // #9682: remove data so that it's not used in an eventual retry
607 // Add or update anti-cache param if needed 551 delete s.data;
608 if ( s.cache === false ) { 552 }
Line 609... Line 553...
609 cacheURL = cacheURL.replace( rantiCache, "$1" ); 553  
610 uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached; 554 // Add anti-cache in url if needed
611 } 555 if ( s.cache === false ) {
Line 635... Line 579...
635 } 579 }
Line 636... Line 580...
636   580  
637 // Set the Accepts header for the server, depending on the dataType 581 // Set the Accepts header for the server, depending on the dataType
638 jqXHR.setRequestHeader( 582 jqXHR.setRequestHeader(
639 "Accept", 583 "Accept",
640 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ? -  
641 s.accepts[ s.dataTypes[ 0 ] ] + 584 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
642 ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : 585 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
643 s.accepts[ "*" ] 586 s.accepts[ "*" ]
Line 644... Line 587...
644 ); 587 );
645   588  
646 // Check for headers option 589 // Check for headers option
647 for ( i in s.headers ) { 590 for ( i in s.headers ) {
Line 648... Line 591...
648 jqXHR.setRequestHeader( i, s.headers[ i ] ); 591 jqXHR.setRequestHeader( i, s.headers[ i ] );
649 } -  
650   592 }
651 // Allow custom headers/mimetypes and early abort -  
652 if ( s.beforeSend && 593  
653 ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) { 594 // Allow custom headers/mimetypes and early abort
654   595 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
Line 655... Line 596...
655 // Abort if not done already and return 596 // Abort if not done already and return
656 return jqXHR.abort(); 597 return jqXHR.abort();
Line 657... Line 598...
657 } 598 }
658   599  
659 // Aborting is no longer a cancellation 600 // Aborting is no longer a cancellation
660 strAbort = "abort"; 601 strAbort = "abort";
Line 661... Line 602...
661   602  
662 // Install callbacks on deferreds 603 // Install callbacks on deferreds
Line 663... Line 604...
663 completeDeferred.add( s.complete ); 604 for ( i in { success: 1, error: 1, complete: 1 } ) {
Line 675... Line 616...
675   616  
676 // Send global event 617 // Send global event
677 if ( fireGlobals ) { 618 if ( fireGlobals ) {
678 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] ); 619 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
679 } -  
680   -  
681 // If request was aborted inside ajaxSend, stop there -  
682 if ( completed ) { -  
683 return jqXHR; -  
684 } -  
685   620 }
686 // Timeout 621 // Timeout
687 if ( s.async && s.timeout > 0 ) { 622 if ( s.async && s.timeout > 0 ) {
688 timeoutTimer = window.setTimeout( function() { 623 timeoutTimer = setTimeout(function() {
689 jqXHR.abort( "timeout" ); 624 jqXHR.abort("timeout");
690 }, s.timeout ); 625 }, s.timeout );
Line 691... Line 626...
691 } 626 }
692   627  
693 try { 628 try {
694 completed = false; 629 state = 1;
695 transport.send( requestHeaders, done ); -  
696 } catch ( e ) { 630 transport.send( requestHeaders, done );
697   631 } catch ( e ) {
-   632 // Propagate exception as error if not done
-   633 if ( state < 2 ) {
-   634 done( -1, e );
698 // Rethrow post-completion exceptions 635 // Simply rethrow otherwise
699 if ( completed ) { 636 } else {
700 throw e; -  
701 } -  
702   -  
703 // Propagate others as results 637 throw e;
704 done( -1, e ); 638 }
Line 705... Line 639...
705 } 639 }
706 } 640 }
707   641  
708 // Callback for when everything is done 642 // Callback for when everything is done
Line 709... Line 643...
709 function done( status, nativeStatusText, responses, headers ) { 643 function done( status, nativeStatusText, responses, headers ) {
710 var isSuccess, success, error, response, modified, 644 var isSuccess, success, error, response, modified,
711 statusText = nativeStatusText; 645 statusText = nativeStatusText;
712   646  
Line -... Line 647...
-   647 // Called once
713 // Ignore repeat invocations 648 if ( state === 2 ) {
Line 714... Line 649...
714 if ( completed ) { 649 return;
715 return; 650 }
716 } 651  
717   652 // State is "done" now
Line 718... Line 653...
718 completed = true; 653 state = 2;
719   654  
720 // Clear timeout if it exists 655 // Clear timeout if it exists
Line 746... Line 681...
746 // If successful, handle type chaining 681 // If successful, handle type chaining
747 if ( isSuccess ) { 682 if ( isSuccess ) {
Line 748... Line 683...
748   683  
749 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode. 684 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
750 if ( s.ifModified ) { 685 if ( s.ifModified ) {
751 modified = jqXHR.getResponseHeader( "Last-Modified" ); 686 modified = jqXHR.getResponseHeader("Last-Modified");
752 if ( modified ) { 687 if ( modified ) {
753 jQuery.lastModified[ cacheURL ] = modified; 688 jQuery.lastModified[ cacheURL ] = modified;
754 } 689 }
755 modified = jqXHR.getResponseHeader( "etag" ); 690 modified = jqXHR.getResponseHeader("etag");
756 if ( modified ) { 691 if ( modified ) {
757 jQuery.etag[ cacheURL ] = modified; 692 jQuery.etag[ cacheURL ] = modified;
758 } 693 }
Line 772... Line 707...
772 success = response.data; 707 success = response.data;
773 error = response.error; 708 error = response.error;
774 isSuccess = !error; 709 isSuccess = !error;
775 } 710 }
776 } else { 711 } else {
777   -  
778 // Extract error from statusText and normalize for non-aborts 712 // Extract error from statusText and normalize for non-aborts
779 error = statusText; 713 error = statusText;
780 if ( status || !statusText ) { 714 if ( status || !statusText ) {
781 statusText = "error"; 715 statusText = "error";
782 if ( status < 0 ) { 716 if ( status < 0 ) {
Line 808... Line 742...
808 // Complete 742 // Complete
809 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] ); 743 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
Line 810... Line 744...
810   744  
811 if ( fireGlobals ) { 745 if ( fireGlobals ) {
812 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] ); -  
813   746 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
814 // Handle the global AJAX counter 747 // Handle the global AJAX counter
815 if ( !( --jQuery.active ) ) { 748 if ( !( --jQuery.active ) ) {
816 jQuery.event.trigger( "ajaxStop" ); 749 jQuery.event.trigger("ajaxStop");
817 } 750 }
818 } 751 }
Line 819... Line 752...
819 } 752 }
Line 826... Line 759...
826 }, 759 },
Line 827... Line 760...
827   760  
828 getScript: function( url, callback ) { 761 getScript: function( url, callback ) {
829 return jQuery.get( url, undefined, callback, "script" ); 762 return jQuery.get( url, undefined, callback, "script" );
830 } 763 }
Line 831... Line 764...
831 } ); 764 });
832   765  
833 jQuery.each( [ "get", "post" ], function( i, method ) { -  
834 jQuery[ method ] = function( url, data, callback, type ) { 766 jQuery.each( [ "get", "post" ], function( i, method ) {
835   767 jQuery[ method ] = function( url, data, callback, type ) {
836 // Shift arguments if data argument was omitted 768 // Shift arguments if data argument was omitted
837 if ( jQuery.isFunction( data ) ) { 769 if ( jQuery.isFunction( data ) ) {
838 type = type || callback; 770 type = type || callback;
839 callback = data; 771 callback = data;
Line 840... Line -...
840 data = undefined; -  
841 } 772 data = undefined;
842   773 }
843 // The url can be an options object (which then must have .url) 774  
844 return jQuery.ajax( jQuery.extend( { 775 return jQuery.ajax({
845 url: url, 776 url: url,
846 type: method, 777 type: method,
847 dataType: type, 778 dataType: type,
848 data: data, 779 data: data,
849 success: callback 780 success: callback
Line 850... Line 781...
850 }, jQuery.isPlainObject( url ) && url ) ); 781 });
851 }; 782 };