scratch – Diff between revs 58 and 125

Subversion Repositories:
Rev:
Show entire fileRegard 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 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 );
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 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 }
Line 297... Line 281...
297 // Last-Modified header cache for next request 281 // Last-Modified header cache for next request
298 lastModified: {}, 282 lastModified: {},
299 etag: {}, 283 etag: {},
Line 300... Line 284...
300   284  
301 ajaxSettings: { 285 ajaxSettings: {
302 url: location.href, 286 url: ajaxLocation,
303 type: "GET", 287 type: "GET",
304 isLocal: rlocalProtocol.test( location.protocol ), 288 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
305 global: true, 289 global: true,
306 processData: true, 290 processData: true,
307 async: true, 291 async: true,
308 contentType: "application/x-www-form-urlencoded; charset=UTF-8", -  
309   292 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
310 /* 293 /*
311 timeout: 0, 294 timeout: 0,
312 data: null, 295 data: null,
313 dataType: null, 296 dataType: null,
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 = {};
Line 466... Line 430...
466 return match == null ? null : match; 430 return match == null ? null : match;
467 }, 431 },
Line 468... Line 432...
468   432  
469 // Raw string 433 // Raw string
470 getAllResponseHeaders: function() { 434 getAllResponseHeaders: function() {
471 return completed ? responseHeadersString : null; 435 return state === 2 ? responseHeadersString : null;
Line 472... Line 436...
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 ) {
478 requestHeadersNames[ name.toLowerCase() ] || name; 442 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
479 requestHeaders[ name ] = value; 443 requestHeaders[ name ] = value;
480 } 444 }
Line 481... Line 445...
481 return this; 445 return this;
482 }, 446 },
483   447  
484 // Overrides response content-type header 448 // Overrides response content-type header
485 overrideMimeType: function( type ) { 449 overrideMimeType: function( type ) {
486 if ( completed == null ) { 450 if ( !state ) {
487 s.mimeType = type; 451 s.mimeType = type;
Line 488... Line 452...
488 } 452 }
489 return this; 453 return this;
490 }, 454 },
491   455  
492 // Status-dependent callbacks 456 // Status-dependent callbacks
493 statusCode: function( map ) { -  
494 var code; -  
495 if ( map ) { -  
496 if ( completed ) { -  
497   -  
498 // Execute the appropriate callbacks -  
499 jqXHR.always( map[ jqXHR.status ] ); 457 statusCode: function( map ) {
-   458 var code;
500 } else { 459 if ( map ) {
501   460 if ( state < 2 ) {
-   461 for ( code in map ) {
-   462 // Lazy-add the new callback in a way that preserves old ones
-   463 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
502 // Lazy-add the new callbacks in a way that preserves old ones 464 }
503 for ( code in map ) { 465 } else {
504 statusCode[ code ] = [ statusCode[ code ], map[ code ] ]; 466 // Execute the appropriate callbacks
505 } 467 jqXHR.always( map[ jqXHR.status ] );
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 }
Line 585... Line 537...
585 // Determine if request has content 537 // Determine if request has content
586 s.hasContent = !rnoContent.test( s.type ); 538 s.hasContent = !rnoContent.test( s.type );
Line 587... Line 539...
587   539  
588 // Save the URL in case we're toying with the If-Modified-Since 540 // 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 541 // and/or If-None-Match header later on
Line 591... Line 542...
591 cacheURL = s.url.replace( rhash, "" ); 542 cacheURL = s.url;
592   543  
Line 593... Line -...
593 // More options handling for requests with no content -  
594 if ( !s.hasContent ) { -  
595   -  
596 // Remember the hash so we can put it back 544 // More options handling for requests with no content
597 uncached = s.url.slice( cacheURL.length ); 545 if ( !s.hasContent ) {
598   546  
599 // If data is available, append data to url -  
600 if ( s.data ) { 547 // If data is available, append data to url
601 cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data; 548 if ( s.data ) {
602   549 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
Line 603... Line 550...
603 // #9682: remove data so that it's not used in an eventual retry 550 // #9682: remove data so that it's not used in an eventual retry
604 delete s.data; 551 delete s.data;
605 } 552 }
606   -  
607 // Add or update anti-cache param if needed -  
Line 608... Line 553...
608 if ( s.cache === false ) { 553  
609 cacheURL = cacheURL.replace( rantiCache, "$1" ); 554 // Add anti-cache in url if needed
Line 610... Line -...
610 uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached; -  
611 } 555 if ( s.cache === false ) {
612   556 s.url = rts.test( cacheURL ) ?
613 // Put hash and anti-cache on the URL that will be requested (gh-1732) 557  
614 s.url = cacheURL + uncached; 558 // If there is already a '_' parameter, set its value
Line 615... Line 559...
615   559 cacheURL.replace( rts, "$1_=" + nonce++ ) :
616 // Change '%20' to '+' if this is encoded form body content (gh-2658) 560  
617 } else if ( s.data && s.processData && 561 // Otherwise add one to the end
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 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 }
Line 830... Line 763...
830 } 763 }
831 } ); 764 });
Line 832... Line 765...
832   765  
833 jQuery.each( [ "get", "post" ], function( i, method ) { 766 jQuery.each( [ "get", "post" ], function( i, method ) {
834 jQuery[ method ] = function( url, data, callback, type ) { -  
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;
840 data = undefined; 772 data = undefined;
Line 841... Line -...
841 } -  
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
850 }, jQuery.isPlainObject( url ) && url ) ); 781 });
Line 851... Line 782...
851 }; 782 };
852 } ); 783 });