a1a3bc73
Luigi Serra
graphs updates
|
1
|
define( [
|
74249687
Luigi Serra
Cross browser con...
|
2
|
"./core",
|
a1a3bc73
Luigi Serra
graphs updates
|
3
|
"./var/document",
|
74249687
Luigi Serra
Cross browser con...
|
4
|
"./var/rnotwhite",
|
a1a3bc73
Luigi Serra
graphs updates
|
5
|
"./ajax/var/location",
|
74249687
Luigi Serra
Cross browser con...
|
6
7
|
"./ajax/var/nonce",
"./ajax/var/rquery",
|
a1a3bc73
Luigi Serra
graphs updates
|
8
|
|
74249687
Luigi Serra
Cross browser con...
|
9
10
11
|
"./core/init",
"./ajax/parseJSON",
"./ajax/parseXML",
|
a1a3bc73
Luigi Serra
graphs updates
|
12
|
"./event/trigger",
|
74249687
Luigi Serra
Cross browser con...
|
13
|
"./deferred"
|
a1a3bc73
Luigi Serra
graphs updates
|
14
|
], function( jQuery, document, rnotwhite, location, nonce, rquery ) {
|
74249687
Luigi Serra
Cross browser con...
|
15
16
17
18
19
|
var
rhash = /#.*$/,
rts = /([?&])_=[^&]*/,
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
a1a3bc73
Luigi Serra
graphs updates
|
20
|
|
74249687
Luigi Serra
Cross browser con...
|
21
22
23
24
|
// #7653, #8125, #8152: local protocol detection
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
rnoContent = /^(?:GET|HEAD)$/,
rprotocol = /^\/\//,
|
74249687
Luigi Serra
Cross browser con...
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/* 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
allTypes = "*/".concat( "*" ),
|
a1a3bc73
Luigi Serra
graphs updates
|
47
48
49
|
// Anchor tag for parsing the document origin
originAnchor = document.createElement( "a" );
originAnchor.href = location.href;
|
74249687
Luigi Serra
Cross browser con...
|
50
51
52
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,
dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
if ( jQuery.isFunction( func ) ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
67
|
|
74249687
Luigi Serra
Cross browser con...
|
68
|
// For each dataType in the dataTypeExpression
|
a1a3bc73
Luigi Serra
graphs updates
|
69
70
|
while ( ( dataType = dataTypes[ i++ ] ) ) {
|
74249687
Luigi Serra
Cross browser con...
|
71
|
// Prepend if requested
|
a1a3bc73
Luigi Serra
graphs updates
|
72
|
if ( dataType[ 0 ] === "+" ) {
|
74249687
Luigi Serra
Cross browser con...
|
73
|
dataType = dataType.slice( 1 ) || "*";
|
a1a3bc73
Luigi Serra
graphs updates
|
74
|
( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
|
74249687
Luigi Serra
Cross browser con...
|
75
76
77
|
// Otherwise append
} else {
|
a1a3bc73
Luigi Serra
graphs updates
|
78
|
( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
|
74249687
Luigi Serra
Cross browser con...
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
}
}
}
};
}
// 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 );
|
a1a3bc73
Luigi Serra
graphs updates
|
96
97
98
|
if ( typeof dataTypeOrTransport === "string" &&
!seekingTransport && !inspected[ dataTypeOrTransport ] ) {
|
74249687
Luigi Serra
Cross browser con...
|
99
100
101
102
103
104
|
options.dataTypes.unshift( dataTypeOrTransport );
inspect( dataTypeOrTransport );
return false;
} else if ( seekingTransport ) {
return !( selected = dataTypeOrTransport );
}
|
a1a3bc73
Luigi Serra
graphs updates
|
105
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
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 ) {
var key, deep,
flatOptions = jQuery.ajaxSettings.flatOptions || {};
for ( key in src ) {
if ( src[ key ] !== undefined ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
121
|
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
|
74249687
Luigi Serra
Cross browser con...
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
}
}
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 ) {
var ct, type, finalDataType, firstDataType,
contents = s.contents,
dataTypes = s.dataTypes;
// Remove auto dataType and get content-type in the process
while ( dataTypes[ 0 ] === "*" ) {
dataTypes.shift();
if ( ct === undefined ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
145
|
ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
|
74249687
Luigi Serra
Cross browser con...
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
}
}
// 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 {
|
a1a3bc73
Luigi Serra
graphs updates
|
163
|
|
74249687
Luigi Serra
Cross browser con...
|
164
165
|
// Try convertible dataTypes
for ( type in responses ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
166
|
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
|
74249687
Luigi Serra
Cross browser con...
|
167
168
169
170
171
172
173
|
finalDataType = type;
break;
}
if ( !firstDataType ) {
firstDataType = type;
}
}
|
a1a3bc73
Luigi Serra
graphs updates
|
174
|
|
74249687
Luigi Serra
Cross browser con...
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
// 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 = {},
|
a1a3bc73
Luigi Serra
graphs updates
|
196
|
|
74249687
Luigi Serra
Cross browser con...
|
197
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
|
// 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 ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
249
|
|
74249687
Luigi Serra
Cross browser con...
|
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
// 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
|
a1a3bc73
Luigi Serra
graphs updates
|
269
|
if ( conv && s.throws ) {
|
74249687
Luigi Serra
Cross browser con...
|
270
271
272
273
274
|
response = conv( response );
} else {
try {
response = conv( response );
} catch ( e ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
275
276
277
278
|
return {
state: "parsererror",
error: conv ? e : "No conversion from " + prev + " to " + current
};
|
74249687
Luigi Serra
Cross browser con...
|
279
280
281
282
283
284
285
286
287
288
|
}
}
}
}
}
}
return { state: "success", data: response };
}
|
a1a3bc73
Luigi Serra
graphs updates
|
289
|
jQuery.extend( {
|
74249687
Luigi Serra
Cross browser con...
|
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: {
|
a1a3bc73
Luigi Serra
graphs updates
|
299
|
url: location.href,
|
74249687
Luigi Serra
Cross browser con...
|
300
|
type: "GET",
|
a1a3bc73
Luigi Serra
graphs updates
|
301
|
isLocal: rlocalProtocol.test( location.protocol ),
|
74249687
Luigi Serra
Cross browser con...
|
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
global: true,
processData: true,
async: true,
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
/*
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: {
|
a1a3bc73
Luigi Serra
graphs updates
|
327
328
329
|
xml: /\bxml\b/,
html: /\bhtml/,
json: /\bjson\b/
|
74249687
Luigi Serra
Cross browser con...
|
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
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
393
|
},
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
"text json": jQuery.parseJSON,
// 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 || {};
var transport,
|
a1a3bc73
Luigi Serra
graphs updates
|
394
|
|
74249687
Luigi Serra
Cross browser con...
|
395
396
|
// URL without anti-cache param
cacheURL,
|
a1a3bc73
Luigi Serra
graphs updates
|
397
|
|
74249687
Luigi Serra
Cross browser con...
|
398
399
400
|
// Response headers
responseHeadersString,
responseHeaders,
|
a1a3bc73
Luigi Serra
graphs updates
|
401
|
|
74249687
Luigi Serra
Cross browser con...
|
402
403
|
// timeout handle
timeoutTimer,
|
a1a3bc73
Luigi Serra
graphs updates
|
404
405
406
407
|
// Url cleanup var
urlAnchor,
|
74249687
Luigi Serra
Cross browser con...
|
408
409
|
// To know if global events are to be dispatched
fireGlobals,
|
a1a3bc73
Luigi Serra
graphs updates
|
410
|
|
74249687
Luigi Serra
Cross browser con...
|
411
412
|
// Loop variable
i,
|
a1a3bc73
Luigi Serra
graphs updates
|
413
|
|
74249687
Luigi Serra
Cross browser con...
|
414
415
|
// Create the final options object
s = jQuery.ajaxSetup( {}, options ),
|
a1a3bc73
Luigi Serra
graphs updates
|
416
|
|
74249687
Luigi Serra
Cross browser con...
|
417
418
|
// Callbacks context
callbackContext = s.context || s,
|
a1a3bc73
Luigi Serra
graphs updates
|
419
|
|
74249687
Luigi Serra
Cross browser con...
|
420
|
// Context for global events is callbackContext if it is a DOM node or jQuery collection
|
a1a3bc73
Luigi Serra
graphs updates
|
421
422
423
424
425
|
globalEventContext = s.context &&
( callbackContext.nodeType || callbackContext.jquery ) ?
jQuery( callbackContext ) :
jQuery.event,
|
74249687
Luigi Serra
Cross browser con...
|
426
427
|
// Deferreds
deferred = jQuery.Deferred(),
|
a1a3bc73
Luigi Serra
graphs updates
|
428
429
|
completeDeferred = jQuery.Callbacks( "once memory" ),
|
74249687
Luigi Serra
Cross browser con...
|
430
431
|
// Status-dependent callbacks
statusCode = s.statusCode || {},
|
a1a3bc73
Luigi Serra
graphs updates
|
432
|
|
74249687
Luigi Serra
Cross browser con...
|
433
434
435
|
// Headers (they are sent all at once)
requestHeaders = {},
requestHeadersNames = {},
|
a1a3bc73
Luigi Serra
graphs updates
|
436
|
|
74249687
Luigi Serra
Cross browser con...
|
437
438
|
// The jqXHR state
state = 0,
|
a1a3bc73
Luigi Serra
graphs updates
|
439
|
|
74249687
Luigi Serra
Cross browser con...
|
440
441
|
// Default abort message
strAbort = "canceled",
|
a1a3bc73
Luigi Serra
graphs updates
|
442
|
|
74249687
Luigi Serra
Cross browser con...
|
443
444
445
446
447
448
449
450
451
452
|
// Fake xhr
jqXHR = {
readyState: 0,
// Builds headers hashtable if needed
getResponseHeader: function( key ) {
var match;
if ( state === 2 ) {
if ( !responseHeaders ) {
responseHeaders = {};
|
a1a3bc73
Luigi Serra
graphs updates
|
453
454
|
while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
|
74249687
Luigi Serra
Cross browser con...
|
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
}
}
match = responseHeaders[ key.toLowerCase() ];
}
return match == null ? null : match;
},
// Raw string
getAllResponseHeaders: function() {
return state === 2 ? responseHeadersString : null;
},
// Caches the header
setRequestHeader: function( name, value ) {
var lname = name.toLowerCase();
if ( !state ) {
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
requestHeaders[ name ] = value;
}
return this;
},
// Overrides response content-type header
overrideMimeType: function( type ) {
if ( !state ) {
s.mimeType = type;
}
return this;
},
// Status-dependent callbacks
statusCode: function( map ) {
var code;
if ( map ) {
if ( state < 2 ) {
for ( code in map ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
491
|
|
74249687
Luigi Serra
Cross browser con...
|
492
493
494
495
|
// Lazy-add the new callback in a way that preserves old ones
statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
}
} else {
|
a1a3bc73
Luigi Serra
graphs updates
|
496
|
|
74249687
Luigi Serra
Cross browser con...
|
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
// Execute the appropriate callbacks
jqXHR.always( map[ jqXHR.status ] );
}
}
return this;
},
// Cancel the request
abort: function( statusText ) {
var finalText = statusText || strAbort;
if ( transport ) {
transport.abort( finalText );
}
done( 0, finalText );
return this;
}
};
// Attach deferreds
deferred.promise( jqXHR ).complete = completeDeferred.add;
jqXHR.success = jqXHR.done;
jqXHR.error = jqXHR.fail;
// Remove hash character (#7531: and string promotion)
// Add protocol if not provided (prefilters might expect it)
// Handle falsy url in the settings object (#10093: consistency with old signature)
// We also use the url parameter if available
|
a1a3bc73
Luigi Serra
graphs updates
|
524
525
|
s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" )
.replace( rprotocol, location.protocol + "//" );
|
74249687
Luigi Serra
Cross browser con...
|
526
527
528
529
530
531
532
|
// Alias method option to type as per ticket #12004
s.type = options.method || options.type || s.method || s.type;
// Extract dataTypes list
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
|
a1a3bc73
Luigi Serra
graphs updates
|
533
|
// A cross-domain request is in order when the origin doesn't match the current origin.
|
74249687
Luigi Serra
Cross browser con...
|
534
|
if ( s.crossDomain == null ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
urlAnchor = document.createElement( "a" );
// Support: IE8-11+
// IE throws exception if url is malformed, e.g. http://example.com:80x/
try {
urlAnchor.href = s.url;
// Support: IE8-11+
// 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;
}
|
74249687
Luigi Serra
Cross browser con...
|
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
}
// 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
if ( state === 2 ) {
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 ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
574
|
jQuery.event.trigger( "ajaxStart" );
|
74249687
Luigi Serra
Cross browser con...
|
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
}
// 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
cacheURL = s.url;
// More options handling for requests with no content
if ( !s.hasContent ) {
// If data is available, append data to url
if ( s.data ) {
cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
|
a1a3bc73
Luigi Serra
graphs updates
|
593
|
|
74249687
Luigi Serra
Cross browser con...
|
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
// #9682: remove data so that it's not used in an eventual retry
delete s.data;
}
// Add anti-cache in url if needed
if ( s.cache === false ) {
s.url = rts.test( cacheURL ) ?
// If there is already a '_' parameter, set its value
cacheURL.replace( rts, "$1_=" + nonce++ ) :
// Otherwise add one to the end
cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
}
}
// 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",
|
a1a3bc73
Luigi Serra
graphs updates
|
628
629
630
|
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
s.accepts[ s.dataTypes[ 0 ] ] +
( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
|
74249687
Luigi Serra
Cross browser con...
|
631
632
633
634
635
636
637
638
639
|
s.accepts[ "*" ]
);
// Check for headers option
for ( i in s.headers ) {
jqXHR.setRequestHeader( i, s.headers[ i ] );
}
// Allow custom headers/mimetypes and early abort
|
a1a3bc73
Luigi Serra
graphs updates
|
640
641
642
|
if ( s.beforeSend &&
( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
|
74249687
Luigi Serra
Cross browser con...
|
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
|
// Abort if not done already and return
return jqXHR.abort();
}
// Aborting is no longer a cancellation
strAbort = "abort";
// Install callbacks on deferreds
for ( i in { success: 1, error: 1, complete: 1 } ) {
jqXHR[ i ]( s[ i ] );
}
// 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 ] );
}
|
a1a3bc73
Luigi Serra
graphs updates
|
668
669
670
671
672
673
|
// If request was aborted inside ajaxSend, stop there
if ( state === 2 ) {
return jqXHR;
}
|
74249687
Luigi Serra
Cross browser con...
|
674
675
|
// Timeout
if ( s.async && s.timeout > 0 ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
676
677
|
timeoutTimer = window.setTimeout( function() {
jqXHR.abort( "timeout" );
|
74249687
Luigi Serra
Cross browser con...
|
678
679
680
681
682
683
684
|
}, s.timeout );
}
try {
state = 1;
transport.send( requestHeaders, done );
} catch ( e ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
685
|
|
74249687
Luigi Serra
Cross browser con...
|
686
687
688
|
// Propagate exception as error if not done
if ( state < 2 ) {
done( -1, e );
|
a1a3bc73
Luigi Serra
graphs updates
|
689
|
|
74249687
Luigi Serra
Cross browser con...
|
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
// Simply rethrow otherwise
} else {
throw e;
}
}
}
// Callback for when everything is done
function done( status, nativeStatusText, responses, headers ) {
var isSuccess, success, error, response, modified,
statusText = nativeStatusText;
// Called once
if ( state === 2 ) {
return;
}
// State is "done" now
state = 2;
// Clear timeout if it exists
if ( timeoutTimer ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
712
|
window.clearTimeout( timeoutTimer );
|
74249687
Luigi Serra
Cross browser con...
|
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
|
}
// 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 ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
741
|
modified = jqXHR.getResponseHeader( "Last-Modified" );
|
74249687
Luigi Serra
Cross browser con...
|
742
743
744
|
if ( modified ) {
jQuery.lastModified[ cacheURL ] = modified;
}
|
a1a3bc73
Luigi Serra
graphs updates
|
745
|
modified = jqXHR.getResponseHeader( "etag" );
|
74249687
Luigi Serra
Cross browser con...
|
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
|
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 {
|
a1a3bc73
Luigi Serra
graphs updates
|
767
|
|
74249687
Luigi Serra
Cross browser con...
|
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
|
// Extract error from statusText and normalize for non-aborts
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 ] );
|
a1a3bc73
Luigi Serra
graphs updates
|
803
|
|
74249687
Luigi Serra
Cross browser con...
|
804
805
|
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
806
|
jQuery.event.trigger( "ajaxStop" );
|
74249687
Luigi Serra
Cross browser con...
|
807
808
809
810
811
812
813
814
815
816
817
818
819
820
|
}
}
}
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" );
}
|
a1a3bc73
Luigi Serra
graphs updates
|
821
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
822
823
824
|
jQuery.each( [ "get", "post" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
|
a1a3bc73
Luigi Serra
graphs updates
|
825
|
|
74249687
Luigi Serra
Cross browser con...
|
826
827
828
829
830
831
832
|
// Shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
|
a1a3bc73
Luigi Serra
graphs updates
|
833
834
|
// The url can be an options object (which then must have .url)
return jQuery.ajax( jQuery.extend( {
|
74249687
Luigi Serra
Cross browser con...
|
835
836
837
838
839
|
url: url,
type: method,
dataType: type,
data: data,
success: callback
|
a1a3bc73
Luigi Serra
graphs updates
|
840
|
}, jQuery.isPlainObject( url ) && url ) );
|
74249687
Luigi Serra
Cross browser con...
|
841
|
};
|
a1a3bc73
Luigi Serra
graphs updates
|
842
|
} );
|
74249687
Luigi Serra
Cross browser con...
|
843
844
|
return jQuery;
|
a1a3bc73
Luigi Serra
graphs updates
|
845
|
} );
|