c5169e0e
Renato De Donato
a new hope
|
1
|
define([
|
74249687
Luigi Serra
Cross browser con...
|
2
|
"./core",
|
74249687
Luigi Serra
Cross browser con...
|
3
|
"./var/rnotwhite",
|
74249687
Luigi Serra
Cross browser con...
|
4
5
|
"./ajax/var/nonce",
"./ajax/var/rquery",
|
74249687
Luigi Serra
Cross browser con...
|
6
7
8
|
"./core/init",
"./ajax/parseJSON",
"./ajax/parseXML",
|
74249687
Luigi Serra
Cross browser con...
|
9
|
"./deferred"
|
c5169e0e
Renato De Donato
a new hope
|
10
|
], function( jQuery, rnotwhite, nonce, rquery ) {
|
74249687
Luigi Serra
Cross browser con...
|
11
12
13
14
15
|
var
rhash = /#.*$/,
rts = /([?&])_=[^&]*/,
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
74249687
Luigi Serra
Cross browser con...
|
16
17
18
19
|
// #7653, #8125, #8152: local protocol detection
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
rnoContent = /^(?:GET|HEAD)$/,
rprotocol = /^\/\//,
|
c5169e0e
Renato De Donato
a new hope
|
20
|
rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
|
74249687
Luigi Serra
Cross browser con...
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/* 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( "*" ),
|
c5169e0e
Renato De Donato
a new hope
|
43
44
45
46
47
|
// Document location
ajaxLocation = window.location.href,
// Segment location into parts
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
|
74249687
Luigi Serra
Cross browser con...
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// 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 ) ) {
|
74249687
Luigi Serra
Cross browser con...
|
65
|
// For each dataType in the dataTypeExpression
|
c5169e0e
Renato De Donato
a new hope
|
66
|
while ( (dataType = dataTypes[i++]) ) {
|
74249687
Luigi Serra
Cross browser con...
|
67
|
// Prepend if requested
|
c5169e0e
Renato De Donato
a new hope
|
68
|
if ( dataType[0] === "+" ) {
|
74249687
Luigi Serra
Cross browser con...
|
69
|
dataType = dataType.slice( 1 ) || "*";
|
c5169e0e
Renato De Donato
a new hope
|
70
|
(structure[ dataType ] = structure[ dataType ] || []).unshift( func );
|
74249687
Luigi Serra
Cross browser con...
|
71
72
73
|
// Otherwise append
} else {
|
c5169e0e
Renato De Donato
a new hope
|
74
|
(structure[ dataType ] = structure[ dataType ] || []).push( func );
|
74249687
Luigi Serra
Cross browser con...
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
}
}
}
};
}
// 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 );
|
c5169e0e
Renato De Donato
a new hope
|
92
|
if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
|
74249687
Luigi Serra
Cross browser con...
|
93
94
95
96
97
98
|
options.dataTypes.unshift( dataTypeOrTransport );
inspect( dataTypeOrTransport );
return false;
} else if ( seekingTransport ) {
return !( selected = dataTypeOrTransport );
}
|
c5169e0e
Renato De Donato
a new hope
|
99
|
});
|
74249687
Luigi Serra
Cross browser con...
|
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
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 ) {
|
c5169e0e
Renato De Donato
a new hope
|
115
|
( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
|
74249687
Luigi Serra
Cross browser con...
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
}
}
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 ) {
|
c5169e0e
Renato De Donato
a new hope
|
139
|
ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
|
74249687
Luigi Serra
Cross browser con...
|
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
}
}
// 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 {
|
74249687
Luigi Serra
Cross browser con...
|
157
158
|
// Try convertible dataTypes
for ( type in responses ) {
|
c5169e0e
Renato De Donato
a new hope
|
159
|
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
|
74249687
Luigi Serra
Cross browser con...
|
160
161
162
163
164
165
166
|
finalDataType = type;
break;
}
if ( !firstDataType ) {
firstDataType = type;
}
}
|
74249687
Luigi Serra
Cross browser con...
|
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
// 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 = {},
|
74249687
Luigi Serra
Cross browser con...
|
188
189
190
191
192
193
194
195
196
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
|
// 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 ) {
|
74249687
Luigi Serra
Cross browser con...
|
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
// 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
|
c5169e0e
Renato De Donato
a new hope
|
259
|
if ( conv && s[ "throws" ] ) {
|
74249687
Luigi Serra
Cross browser con...
|
260
261
262
263
264
|
response = conv( response );
} else {
try {
response = conv( response );
} catch ( e ) {
|
c5169e0e
Renato De Donato
a new hope
|
265
|
return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
|
74249687
Luigi Serra
Cross browser con...
|
266
267
268
269
270
271
272
273
274
275
|
}
}
}
}
}
}
return { state: "success", data: response };
}
|
c5169e0e
Renato De Donato
a new hope
|
276
|
jQuery.extend({
|
74249687
Luigi Serra
Cross browser con...
|
277
278
279
280
281
282
283
284
285
|
// Counter for holding the number of active queries
active: 0,
// Last-Modified header cache for next request
lastModified: {},
etag: {},
ajaxSettings: {
|
c5169e0e
Renato De Donato
a new hope
|
286
|
url: ajaxLocation,
|
74249687
Luigi Serra
Cross browser con...
|
287
|
type: "GET",
|
c5169e0e
Renato De Donato
a new hope
|
288
|
isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
|
74249687
Luigi Serra
Cross browser con...
|
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
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: {
|
c5169e0e
Renato De Donato
a new hope
|
314
315
316
|
xml: /xml/,
html: /html/,
json: /json/
|
74249687
Luigi Serra
Cross browser con...
|
317
318
319
320
321
322
323
324
325
326
327
328
329
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
|
},
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,
|
74249687
Luigi Serra
Cross browser con...
|
381
382
|
// URL without anti-cache param
cacheURL,
|
74249687
Luigi Serra
Cross browser con...
|
383
384
385
|
// Response headers
responseHeadersString,
responseHeaders,
|
74249687
Luigi Serra
Cross browser con...
|
386
387
|
// timeout handle
timeoutTimer,
|
c5169e0e
Renato De Donato
a new hope
|
388
389
|
// Cross-domain detection vars
parts,
|
74249687
Luigi Serra
Cross browser con...
|
390
391
|
// To know if global events are to be dispatched
fireGlobals,
|
74249687
Luigi Serra
Cross browser con...
|
392
393
|
// Loop variable
i,
|
74249687
Luigi Serra
Cross browser con...
|
394
395
|
// Create the final options object
s = jQuery.ajaxSetup( {}, options ),
|
74249687
Luigi Serra
Cross browser con...
|
396
397
|
// Callbacks context
callbackContext = s.context || s,
|
74249687
Luigi Serra
Cross browser con...
|
398
|
// Context for global events is callbackContext if it is a DOM node or jQuery collection
|
c5169e0e
Renato De Donato
a new hope
|
399
400
401
|
globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
jQuery( callbackContext ) :
jQuery.event,
|
74249687
Luigi Serra
Cross browser con...
|
402
403
|
// Deferreds
deferred = jQuery.Deferred(),
|
c5169e0e
Renato De Donato
a new hope
|
404
|
completeDeferred = jQuery.Callbacks("once memory"),
|
74249687
Luigi Serra
Cross browser con...
|
405
406
|
// Status-dependent callbacks
statusCode = s.statusCode || {},
|
74249687
Luigi Serra
Cross browser con...
|
407
408
409
|
// Headers (they are sent all at once)
requestHeaders = {},
requestHeadersNames = {},
|
74249687
Luigi Serra
Cross browser con...
|
410
411
|
// The jqXHR state
state = 0,
|
74249687
Luigi Serra
Cross browser con...
|
412
413
|
// Default abort message
strAbort = "canceled",
|
74249687
Luigi Serra
Cross browser con...
|
414
415
416
417
418
419
420
421
422
423
|
// Fake xhr
jqXHR = {
readyState: 0,
// Builds headers hashtable if needed
getResponseHeader: function( key ) {
var match;
if ( state === 2 ) {
if ( !responseHeaders ) {
responseHeaders = {};
|
c5169e0e
Renato De Donato
a new hope
|
424
425
|
while ( (match = rheaders.exec( responseHeadersString )) ) {
responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
|
74249687
Luigi Serra
Cross browser con...
|
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
}
}
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 ) {
|
74249687
Luigi Serra
Cross browser con...
|
462
463
464
465
|
// Lazy-add the new callback in a way that preserves old ones
statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
}
} else {
|
74249687
Luigi Serra
Cross browser con...
|
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
491
492
|
// 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
|
c5169e0e
Renato De Donato
a new hope
|
493
494
|
s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
.replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
|
74249687
Luigi Serra
Cross browser con...
|
495
496
497
498
499
500
501
|
// 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 ) || [ "" ];
|
c5169e0e
Renato De Donato
a new hope
|
502
|
// A cross-domain request is in order when we have a protocol:host:port mismatch
|
74249687
Luigi Serra
Cross browser con...
|
503
|
if ( s.crossDomain == null ) {
|
c5169e0e
Renato De Donato
a new hope
|
504
505
506
507
508
509
|
parts = rurl.exec( s.url.toLowerCase() );
s.crossDomain = !!( parts &&
( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
);
|
74249687
Luigi Serra
Cross browser con...
|
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
}
// 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 ) {
|
c5169e0e
Renato De Donato
a new hope
|
531
|
jQuery.event.trigger("ajaxStart");
|
74249687
Luigi Serra
Cross browser con...
|
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
}
// 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 );
|
74249687
Luigi Serra
Cross browser con...
|
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
|
// #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",
|
c5169e0e
Renato De Donato
a new hope
|
584
585
|
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...
|
586
587
588
589
590
591
592
593
594
|
s.accepts[ "*" ]
);
// Check for headers option
for ( i in s.headers ) {
jqXHR.setRequestHeader( i, s.headers[ i ] );
}
// Allow custom headers/mimetypes and early abort
|
c5169e0e
Renato De Donato
a new hope
|
595
|
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
|
74249687
Luigi Serra
Cross browser con...
|
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
|
// 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 ] );
}
|
74249687
Luigi Serra
Cross browser con...
|
621
622
|
// Timeout
if ( s.async && s.timeout > 0 ) {
|
c5169e0e
Renato De Donato
a new hope
|
623
624
|
timeoutTimer = setTimeout(function() {
jqXHR.abort("timeout");
|
74249687
Luigi Serra
Cross browser con...
|
625
626
627
628
629
630
631
|
}, s.timeout );
}
try {
state = 1;
transport.send( requestHeaders, done );
} catch ( e ) {
|
74249687
Luigi Serra
Cross browser con...
|
632
633
634
|
// Propagate exception as error if not done
if ( state < 2 ) {
done( -1, e );
|
74249687
Luigi Serra
Cross browser con...
|
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
|
// 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 ) {
|
c5169e0e
Renato De Donato
a new hope
|
657
|
clearTimeout( timeoutTimer );
|
74249687
Luigi Serra
Cross browser con...
|
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
}
// 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 ) {
|
c5169e0e
Renato De Donato
a new hope
|
686
|
modified = jqXHR.getResponseHeader("Last-Modified");
|
74249687
Luigi Serra
Cross browser con...
|
687
688
689
|
if ( modified ) {
jQuery.lastModified[ cacheURL ] = modified;
}
|
c5169e0e
Renato De Donato
a new hope
|
690
|
modified = jqXHR.getResponseHeader("etag");
|
74249687
Luigi Serra
Cross browser con...
|
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
|
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 {
|
74249687
Luigi Serra
Cross browser con...
|
712
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
741
742
743
744
745
746
|
// 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 ] );
|
74249687
Luigi Serra
Cross browser con...
|
747
748
|
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
|
c5169e0e
Renato De Donato
a new hope
|
749
|
jQuery.event.trigger("ajaxStop");
|
74249687
Luigi Serra
Cross browser con...
|
750
751
752
753
754
755
756
757
758
759
760
761
762
763
|
}
}
}
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" );
}
|
c5169e0e
Renato De Donato
a new hope
|
764
|
});
|
74249687
Luigi Serra
Cross browser con...
|
765
766
767
|
jQuery.each( [ "get", "post" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
|
74249687
Luigi Serra
Cross browser con...
|
768
769
770
771
772
773
774
|
// Shift arguments if data argument was omitted
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
|
c5169e0e
Renato De Donato
a new hope
|
775
|
return jQuery.ajax({
|
74249687
Luigi Serra
Cross browser con...
|
776
777
778
779
780
|
url: url,
type: method,
dataType: type,
data: data,
success: callback
|
c5169e0e
Renato De Donato
a new hope
|
781
|
});
|
74249687
Luigi Serra
Cross browser con...
|
782
|
};
|
c5169e0e
Renato De Donato
a new hope
|
783
|
});
|
74249687
Luigi Serra
Cross browser con...
|
784
785
|
return jQuery;
|
c5169e0e
Renato De Donato
a new hope
|
786
|
});
|