root / drupal7 / sites / all / libraries / flexslider-2.5.0 / bower_components / jquery / src / ajax.js @ 0aee3c58
1 |
define([ |
---|---|
2 |
"./core",
|
3 |
"./var/rnotwhite",
|
4 |
"./ajax/var/nonce",
|
5 |
"./ajax/var/rquery",
|
6 |
"./core/init",
|
7 |
"./ajax/parseJSON",
|
8 |
"./ajax/parseXML",
|
9 |
"./deferred"
|
10 |
], function( jQuery, rnotwhite, nonce, rquery ) {
|
11 |
|
12 |
var
|
13 |
// Document location
|
14 |
ajaxLocParts, |
15 |
ajaxLocation, |
16 |
|
17 |
rhash = /#.*$/,
|
18 |
rts = /([?&])_=[^&]*/,
|
19 |
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL |
20 |
// #7653, #8125, #8152: local protocol detection
|
21 |
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
|
22 |
rnoContent = /^(?:GET|HEAD)$/,
|
23 |
rprotocol = /^\/\//,
|
24 |
rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
|
25 |
|
26 |
/* Prefilters
|
27 |
* 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
|
28 |
* 2) These are called:
|
29 |
* - BEFORE asking for a transport
|
30 |
* - AFTER param serialization (s.data is a string if s.processData is true)
|
31 |
* 3) key is the dataType
|
32 |
* 4) the catchall symbol "*" can be used
|
33 |
* 5) execution will start with transport dataType and THEN continue down to "*" if needed
|
34 |
*/
|
35 |
prefilters = {}, |
36 |
|
37 |
/* Transports bindings
|
38 |
* 1) key is the dataType
|
39 |
* 2) the catchall symbol "*" can be used
|
40 |
* 3) selection will start with transport dataType and THEN go to "*" if needed
|
41 |
*/
|
42 |
transports = {}, |
43 |
|
44 |
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
|
45 |
allTypes = "*/".concat("*"); |
46 |
|
47 |
// #8138, IE may throw an exception when accessing
|
48 |
// a field from window.location if document.domain has been set
|
49 |
try {
|
50 |
ajaxLocation = location.href; |
51 |
} catch( e ) {
|
52 |
// Use the href attribute of an A element
|
53 |
// since IE will modify it given document.location
|
54 |
ajaxLocation = document.createElement( "a" );
|
55 |
ajaxLocation.href = "";
|
56 |
ajaxLocation = ajaxLocation.href; |
57 |
} |
58 |
|
59 |
// Segment location into parts
|
60 |
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || []; |
61 |
|
62 |
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
|
63 |
function addToPrefiltersOrTransports( structure ) { |
64 |
|
65 |
// dataTypeExpression is optional and defaults to "*"
|
66 |
return function( dataTypeExpression, func ) { |
67 |
|
68 |
if ( typeof dataTypeExpression !== "string" ) { |
69 |
func = dataTypeExpression; |
70 |
dataTypeExpression = "*";
|
71 |
} |
72 |
|
73 |
var dataType,
|
74 |
i = 0,
|
75 |
dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || []; |
76 |
|
77 |
if ( jQuery.isFunction( func ) ) {
|
78 |
// For each dataType in the dataTypeExpression
|
79 |
while ( (dataType = dataTypes[i++]) ) {
|
80 |
// Prepend if requested
|
81 |
if ( dataType.charAt( 0 ) === "+" ) { |
82 |
dataType = dataType.slice( 1 ) || "*"; |
83 |
(structure[ dataType ] = structure[ dataType ] || []).unshift( func ); |
84 |
|
85 |
// Otherwise append
|
86 |
} else {
|
87 |
(structure[ dataType ] = structure[ dataType ] || []).push( func ); |
88 |
} |
89 |
} |
90 |
} |
91 |
}; |
92 |
} |
93 |
|
94 |
// Base inspection function for prefilters and transports
|
95 |
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) { |
96 |
|
97 |
var inspected = {},
|
98 |
seekingTransport = ( structure === transports ); |
99 |
|
100 |
function inspect( dataType ) { |
101 |
var selected;
|
102 |
inspected[ dataType ] = true;
|
103 |
jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
|
104 |
var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
|
105 |
if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) { |
106 |
options.dataTypes.unshift( dataTypeOrTransport ); |
107 |
inspect( dataTypeOrTransport ); |
108 |
return false; |
109 |
} else if ( seekingTransport ) { |
110 |
return !( selected = dataTypeOrTransport );
|
111 |
} |
112 |
}); |
113 |
return selected;
|
114 |
} |
115 |
|
116 |
return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" ); |
117 |
} |
118 |
|
119 |
// A special extend for ajax options
|
120 |
// that takes "flat" options (not to be deep extended)
|
121 |
// Fixes #9887
|
122 |
function ajaxExtend( target, src ) { |
123 |
var deep, key,
|
124 |
flatOptions = jQuery.ajaxSettings.flatOptions || {}; |
125 |
|
126 |
for ( key in src ) { |
127 |
if ( src[ key ] !== undefined ) { |
128 |
( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ]; |
129 |
} |
130 |
} |
131 |
if ( deep ) {
|
132 |
jQuery.extend( true, target, deep );
|
133 |
} |
134 |
|
135 |
return target;
|
136 |
} |
137 |
|
138 |
/* Handles responses to an ajax request:
|
139 |
* - finds the right dataType (mediates between content-type and expected dataType)
|
140 |
* - returns the corresponding response
|
141 |
*/
|
142 |
function ajaxHandleResponses( s, jqXHR, responses ) { |
143 |
var firstDataType, ct, finalDataType, type,
|
144 |
contents = s.contents, |
145 |
dataTypes = s.dataTypes; |
146 |
|
147 |
// Remove auto dataType and get content-type in the process
|
148 |
while ( dataTypes[ 0 ] === "*" ) { |
149 |
dataTypes.shift(); |
150 |
if ( ct === undefined ) { |
151 |
ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
|
152 |
} |
153 |
} |
154 |
|
155 |
// Check if we're dealing with a known content-type
|
156 |
if ( ct ) {
|
157 |
for ( type in contents ) { |
158 |
if ( contents[ type ] && contents[ type ].test( ct ) ) {
|
159 |
dataTypes.unshift( type ); |
160 |
break;
|
161 |
} |
162 |
} |
163 |
} |
164 |
|
165 |
// Check to see if we have a response for the expected dataType
|
166 |
if ( dataTypes[ 0 ] in responses ) { |
167 |
finalDataType = dataTypes[ 0 ];
|
168 |
} else {
|
169 |
// Try convertible dataTypes
|
170 |
for ( type in responses ) { |
171 |
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) { |
172 |
finalDataType = type; |
173 |
break;
|
174 |
} |
175 |
if ( !firstDataType ) {
|
176 |
firstDataType = type; |
177 |
} |
178 |
} |
179 |
// Or just use first one
|
180 |
finalDataType = finalDataType || firstDataType; |
181 |
} |
182 |
|
183 |
// If we found a dataType
|
184 |
// We add the dataType to the list if needed
|
185 |
// and return the corresponding response
|
186 |
if ( finalDataType ) {
|
187 |
if ( finalDataType !== dataTypes[ 0 ] ) { |
188 |
dataTypes.unshift( finalDataType ); |
189 |
} |
190 |
return responses[ finalDataType ];
|
191 |
} |
192 |
} |
193 |
|
194 |
/* Chain conversions given the request and the original response
|
195 |
* Also sets the responseXXX fields on the jqXHR instance
|
196 |
*/
|
197 |
function ajaxConvert( s, response, jqXHR, isSuccess ) { |
198 |
var conv2, current, conv, tmp, prev,
|
199 |
converters = {}, |
200 |
// Work with a copy of dataTypes in case we need to modify it for conversion
|
201 |
dataTypes = s.dataTypes.slice(); |
202 |
|
203 |
// Create converters map with lowercased keys
|
204 |
if ( dataTypes[ 1 ] ) { |
205 |
for ( conv in s.converters ) { |
206 |
converters[ conv.toLowerCase() ] = s.converters[ conv ]; |
207 |
} |
208 |
} |
209 |
|
210 |
current = dataTypes.shift(); |
211 |
|
212 |
// Convert to each sequential dataType
|
213 |
while ( current ) {
|
214 |
|
215 |
if ( s.responseFields[ current ] ) {
|
216 |
jqXHR[ s.responseFields[ current ] ] = response; |
217 |
} |
218 |
|
219 |
// Apply the dataFilter if provided
|
220 |
if ( !prev && isSuccess && s.dataFilter ) {
|
221 |
response = s.dataFilter( response, s.dataType ); |
222 |
} |
223 |
|
224 |
prev = current; |
225 |
current = dataTypes.shift(); |
226 |
|
227 |
if ( current ) {
|
228 |
|
229 |
// There's only work to do if current dataType is non-auto
|
230 |
if ( current === "*" ) { |
231 |
|
232 |
current = prev; |
233 |
|
234 |
// Convert response if prev dataType is non-auto and differs from current
|
235 |
} else if ( prev !== "*" && prev !== current ) { |
236 |
|
237 |
// Seek a direct converter
|
238 |
conv = converters[ prev + " " + current ] || converters[ "* " + current ]; |
239 |
|
240 |
// If none found, seek a pair
|
241 |
if ( !conv ) {
|
242 |
for ( conv2 in converters ) { |
243 |
|
244 |
// If conv2 outputs current
|
245 |
tmp = conv2.split( " " );
|
246 |
if ( tmp[ 1 ] === current ) { |
247 |
|
248 |
// If prev can be converted to accepted input
|
249 |
conv = converters[ prev + " " + tmp[ 0 ] ] || |
250 |
converters[ "* " + tmp[ 0 ] ]; |
251 |
if ( conv ) {
|
252 |
// Condense equivalence converters
|
253 |
if ( conv === true ) { |
254 |
conv = converters[ conv2 ]; |
255 |
|
256 |
// Otherwise, insert the intermediate dataType
|
257 |
} else if ( converters[ conv2 ] !== true ) { |
258 |
current = tmp[ 0 ];
|
259 |
dataTypes.unshift( tmp[ 1 ] );
|
260 |
} |
261 |
break;
|
262 |
} |
263 |
} |
264 |
} |
265 |
} |
266 |
|
267 |
// Apply converter (if not an equivalence)
|
268 |
if ( conv !== true ) { |
269 |
|
270 |
// Unless errors are allowed to bubble, catch and return them
|
271 |
if ( conv && s[ "throws" ] ) { |
272 |
response = conv( response ); |
273 |
} else {
|
274 |
try {
|
275 |
response = conv( response ); |
276 |
} catch ( e ) {
|
277 |
return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current }; |
278 |
} |
279 |
} |
280 |
} |
281 |
} |
282 |
} |
283 |
} |
284 |
|
285 |
return { state: "success", data: response }; |
286 |
} |
287 |
|
288 |
jQuery.extend({ |
289 |
|
290 |
// Counter for holding the number of active queries
|
291 |
active: 0, |
292 |
|
293 |
// Last-Modified header cache for next request
|
294 |
lastModified: {},
|
295 |
etag: {},
|
296 |
|
297 |
ajaxSettings: {
|
298 |
url: ajaxLocation,
|
299 |
type: "GET", |
300 |
isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ), |
301 |
global: true, |
302 |
processData: true, |
303 |
async: true, |
304 |
contentType: "application/x-www-form-urlencoded; charset=UTF-8", |
305 |
/*
|
306 |
timeout: 0,
|
307 |
data: null,
|
308 |
dataType: null,
|
309 |
username: null,
|
310 |
password: null,
|
311 |
cache: null,
|
312 |
throws: false,
|
313 |
traditional: false,
|
314 |
headers: {},
|
315 |
*/
|
316 |
|
317 |
accepts: {
|
318 |
"*": allTypes,
|
319 |
text: "text/plain", |
320 |
html: "text/html", |
321 |
xml: "application/xml, text/xml", |
322 |
json: "application/json, text/javascript" |
323 |
}, |
324 |
|
325 |
contents: {
|
326 |
xml: /xml/, |
327 |
html: /html/, |
328 |
json: /json/ |
329 |
}, |
330 |
|
331 |
responseFields: {
|
332 |
xml: "responseXML", |
333 |
text: "responseText", |
334 |
json: "responseJSON" |
335 |
}, |
336 |
|
337 |
// Data converters
|
338 |
// Keys separate source (or catchall "*") and destination types with a single space
|
339 |
converters: {
|
340 |
|
341 |
// Convert anything to text
|
342 |
"* text": String,
|
343 |
|
344 |
// Text to html (true = no transformation)
|
345 |
"text html": true, |
346 |
|
347 |
// Evaluate text as a json expression
|
348 |
"text json": jQuery.parseJSON,
|
349 |
|
350 |
// Parse text as xml
|
351 |
"text xml": jQuery.parseXML
|
352 |
}, |
353 |
|
354 |
// For options that shouldn't be deep extended:
|
355 |
// you can add your own custom options here if
|
356 |
// and when you create one that shouldn't be
|
357 |
// deep extended (see ajaxExtend)
|
358 |
flatOptions: {
|
359 |
url: true, |
360 |
context: true |
361 |
} |
362 |
}, |
363 |
|
364 |
// Creates a full fledged settings object into target
|
365 |
// with both ajaxSettings and settings fields.
|
366 |
// If target is omitted, writes into ajaxSettings.
|
367 |
ajaxSetup: function( target, settings ) { |
368 |
return settings ?
|
369 |
|
370 |
// Building a settings object
|
371 |
ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) : |
372 |
|
373 |
// Extending ajaxSettings
|
374 |
ajaxExtend( jQuery.ajaxSettings, target ); |
375 |
}, |
376 |
|
377 |
ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
|
378 |
ajaxTransport: addToPrefiltersOrTransports( transports ),
|
379 |
|
380 |
// Main method
|
381 |
ajax: function( url, options ) { |
382 |
|
383 |
// If url is an object, simulate pre-1.5 signature
|
384 |
if ( typeof url === "object" ) { |
385 |
options = url; |
386 |
url = undefined;
|
387 |
} |
388 |
|
389 |
// Force options to be an object
|
390 |
options = options || {}; |
391 |
|
392 |
var // Cross-domain detection vars |
393 |
parts, |
394 |
// Loop variable
|
395 |
i, |
396 |
// URL without anti-cache param
|
397 |
cacheURL, |
398 |
// Response headers as string
|
399 |
responseHeadersString, |
400 |
// timeout handle
|
401 |
timeoutTimer, |
402 |
|
403 |
// To know if global events are to be dispatched
|
404 |
fireGlobals, |
405 |
|
406 |
transport, |
407 |
// Response headers
|
408 |
responseHeaders, |
409 |
// Create the final options object
|
410 |
s = jQuery.ajaxSetup( {}, options ), |
411 |
// Callbacks context
|
412 |
callbackContext = s.context || s, |
413 |
// Context for global events is callbackContext if it is a DOM node or jQuery collection
|
414 |
globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ? |
415 |
jQuery( callbackContext ) : |
416 |
jQuery.event, |
417 |
// Deferreds
|
418 |
deferred = jQuery.Deferred(), |
419 |
completeDeferred = jQuery.Callbacks("once memory"),
|
420 |
// Status-dependent callbacks
|
421 |
statusCode = s.statusCode || {}, |
422 |
// Headers (they are sent all at once)
|
423 |
requestHeaders = {}, |
424 |
requestHeadersNames = {}, |
425 |
// The jqXHR state
|
426 |
state = 0,
|
427 |
// Default abort message
|
428 |
strAbort = "canceled",
|
429 |
// Fake xhr
|
430 |
jqXHR = { |
431 |
readyState: 0, |
432 |
|
433 |
// Builds headers hashtable if needed
|
434 |
getResponseHeader: function( key ) { |
435 |
var match;
|
436 |
if ( state === 2 ) { |
437 |
if ( !responseHeaders ) {
|
438 |
responseHeaders = {}; |
439 |
while ( (match = rheaders.exec( responseHeadersString )) ) {
|
440 |
responseHeaders[ match[1].toLowerCase() ] = match[ 2 ]; |
441 |
} |
442 |
} |
443 |
match = responseHeaders[ key.toLowerCase() ]; |
444 |
} |
445 |
return match == null ? null : match; |
446 |
}, |
447 |
|
448 |
// Raw string
|
449 |
getAllResponseHeaders: function() { |
450 |
return state === 2 ? responseHeadersString : null; |
451 |
}, |
452 |
|
453 |
// Caches the header
|
454 |
setRequestHeader: function( name, value ) { |
455 |
var lname = name.toLowerCase();
|
456 |
if ( !state ) {
|
457 |
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name; |
458 |
requestHeaders[ name ] = value; |
459 |
} |
460 |
return this; |
461 |
}, |
462 |
|
463 |
// Overrides response content-type header
|
464 |
overrideMimeType: function( type ) { |
465 |
if ( !state ) {
|
466 |
s.mimeType = type; |
467 |
} |
468 |
return this; |
469 |
}, |
470 |
|
471 |
// Status-dependent callbacks
|
472 |
statusCode: function( map ) { |
473 |
var code;
|
474 |
if ( map ) {
|
475 |
if ( state < 2 ) { |
476 |
for ( code in map ) { |
477 |
// Lazy-add the new callback in a way that preserves old ones
|
478 |
statusCode[ code ] = [ statusCode[ code ], map[ code ] ]; |
479 |
} |
480 |
} else {
|
481 |
// Execute the appropriate callbacks
|
482 |
jqXHR.always( map[ jqXHR.status ] ); |
483 |
} |
484 |
} |
485 |
return this; |
486 |
}, |
487 |
|
488 |
// Cancel the request
|
489 |
abort: function( statusText ) { |
490 |
var finalText = statusText || strAbort;
|
491 |
if ( transport ) {
|
492 |
transport.abort( finalText ); |
493 |
} |
494 |
done( 0, finalText );
|
495 |
return this; |
496 |
} |
497 |
}; |
498 |
|
499 |
// Attach deferreds
|
500 |
deferred.promise( jqXHR ).complete = completeDeferred.add; |
501 |
jqXHR.success = jqXHR.done; |
502 |
jqXHR.error = jqXHR.fail; |
503 |
|
504 |
// Remove hash character (#7531: and string promotion)
|
505 |
// Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
|
506 |
// Handle falsy url in the settings object (#10093: consistency with old signature)
|
507 |
// We also use the url parameter if available
|
508 |
s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" ); |
509 |
|
510 |
// Alias method option to type as per ticket #12004
|
511 |
s.type = options.method || options.type || s.method || s.type; |
512 |
|
513 |
// Extract dataTypes list
|
514 |
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ]; |
515 |
|
516 |
// A cross-domain request is in order when we have a protocol:host:port mismatch
|
517 |
if ( s.crossDomain == null ) { |
518 |
parts = rurl.exec( s.url.toLowerCase() ); |
519 |
s.crossDomain = !!( parts && |
520 |
( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] || |
521 |
( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !== |
522 |
( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) ) |
523 |
); |
524 |
} |
525 |
|
526 |
// Convert data if not already a string
|
527 |
if ( s.data && s.processData && typeof s.data !== "string" ) { |
528 |
s.data = jQuery.param( s.data, s.traditional ); |
529 |
} |
530 |
|
531 |
// Apply prefilters
|
532 |
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR ); |
533 |
|
534 |
// If request was aborted inside a prefilter, stop there
|
535 |
if ( state === 2 ) { |
536 |
return jqXHR;
|
537 |
} |
538 |
|
539 |
// We can fire global events as of now if asked to
|
540 |
// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
|
541 |
fireGlobals = jQuery.event && s.global; |
542 |
|
543 |
// Watch for a new set of requests
|
544 |
if ( fireGlobals && jQuery.active++ === 0 ) { |
545 |
jQuery.event.trigger("ajaxStart");
|
546 |
} |
547 |
|
548 |
// Uppercase the type
|
549 |
s.type = s.type.toUpperCase(); |
550 |
|
551 |
// Determine if request has content
|
552 |
s.hasContent = !rnoContent.test( s.type ); |
553 |
|
554 |
// Save the URL in case we're toying with the If-Modified-Since
|
555 |
// and/or If-None-Match header later on
|
556 |
cacheURL = s.url; |
557 |
|
558 |
// More options handling for requests with no content
|
559 |
if ( !s.hasContent ) {
|
560 |
|
561 |
// If data is available, append data to url
|
562 |
if ( s.data ) {
|
563 |
cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data ); |
564 |
// #9682: remove data so that it's not used in an eventual retry
|
565 |
delete s.data;
|
566 |
} |
567 |
|
568 |
// Add anti-cache in url if needed
|
569 |
if ( s.cache === false ) { |
570 |
s.url = rts.test( cacheURL ) ? |
571 |
|
572 |
// If there is already a '_' parameter, set its value
|
573 |
cacheURL.replace( rts, "$1_=" + nonce++ ) :
|
574 |
|
575 |
// Otherwise add one to the end
|
576 |
cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++; |
577 |
} |
578 |
} |
579 |
|
580 |
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
581 |
if ( s.ifModified ) {
|
582 |
if ( jQuery.lastModified[ cacheURL ] ) {
|
583 |
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
|
584 |
} |
585 |
if ( jQuery.etag[ cacheURL ] ) {
|
586 |
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
|
587 |
} |
588 |
} |
589 |
|
590 |
// Set the correct header, if data is being sent
|
591 |
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) { |
592 |
jqXHR.setRequestHeader( "Content-Type", s.contentType );
|
593 |
} |
594 |
|
595 |
// Set the Accepts header for the server, depending on the dataType
|
596 |
jqXHR.setRequestHeader( |
597 |
"Accept",
|
598 |
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ? |
599 |
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) : |
600 |
s.accepts[ "*" ]
|
601 |
); |
602 |
|
603 |
// Check for headers option
|
604 |
for ( i in s.headers ) { |
605 |
jqXHR.setRequestHeader( i, s.headers[ i ] ); |
606 |
} |
607 |
|
608 |
// Allow custom headers/mimetypes and early abort
|
609 |
if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) { |
610 |
// Abort if not done already and return
|
611 |
return jqXHR.abort();
|
612 |
} |
613 |
|
614 |
// aborting is no longer a cancellation
|
615 |
strAbort = "abort";
|
616 |
|
617 |
// Install callbacks on deferreds
|
618 |
for ( i in { success: 1, error: 1, complete: 1 } ) { |
619 |
jqXHR[ i ]( s[ i ] ); |
620 |
} |
621 |
|
622 |
// Get transport
|
623 |
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR ); |
624 |
|
625 |
// If no transport, we auto-abort
|
626 |
if ( !transport ) {
|
627 |
done( -1, "No Transport" ); |
628 |
} else {
|
629 |
jqXHR.readyState = 1;
|
630 |
|
631 |
// Send global event
|
632 |
if ( fireGlobals ) {
|
633 |
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
634 |
} |
635 |
// Timeout
|
636 |
if ( s.async && s.timeout > 0 ) { |
637 |
timeoutTimer = setTimeout(function() {
|
638 |
jqXHR.abort("timeout");
|
639 |
}, s.timeout ); |
640 |
} |
641 |
|
642 |
try {
|
643 |
state = 1;
|
644 |
transport.send( requestHeaders, done ); |
645 |
} catch ( e ) {
|
646 |
// Propagate exception as error if not done
|
647 |
if ( state < 2 ) { |
648 |
done( -1, e );
|
649 |
// Simply rethrow otherwise
|
650 |
} else {
|
651 |
throw e;
|
652 |
} |
653 |
} |
654 |
} |
655 |
|
656 |
// Callback for when everything is done
|
657 |
function done( status, nativeStatusText, responses, headers ) { |
658 |
var isSuccess, success, error, response, modified,
|
659 |
statusText = nativeStatusText; |
660 |
|
661 |
// Called once
|
662 |
if ( state === 2 ) { |
663 |
return;
|
664 |
} |
665 |
|
666 |
// State is "done" now
|
667 |
state = 2;
|
668 |
|
669 |
// Clear timeout if it exists
|
670 |
if ( timeoutTimer ) {
|
671 |
clearTimeout( timeoutTimer ); |
672 |
} |
673 |
|
674 |
// Dereference transport for early garbage collection
|
675 |
// (no matter how long the jqXHR object will be used)
|
676 |
transport = undefined;
|
677 |
|
678 |
// Cache response headers
|
679 |
responseHeadersString = headers || "";
|
680 |
|
681 |
// Set readyState
|
682 |
jqXHR.readyState = status > 0 ? 4 : 0; |
683 |
|
684 |
// Determine if successful
|
685 |
isSuccess = status >= 200 && status < 300 || status === 304; |
686 |
|
687 |
// Get response data
|
688 |
if ( responses ) {
|
689 |
response = ajaxHandleResponses( s, jqXHR, responses ); |
690 |
} |
691 |
|
692 |
// Convert no matter what (that way responseXXX fields are always set)
|
693 |
response = ajaxConvert( s, response, jqXHR, isSuccess ); |
694 |
|
695 |
// If successful, handle type chaining
|
696 |
if ( isSuccess ) {
|
697 |
|
698 |
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
699 |
if ( s.ifModified ) {
|
700 |
modified = jqXHR.getResponseHeader("Last-Modified");
|
701 |
if ( modified ) {
|
702 |
jQuery.lastModified[ cacheURL ] = modified; |
703 |
} |
704 |
modified = jqXHR.getResponseHeader("etag");
|
705 |
if ( modified ) {
|
706 |
jQuery.etag[ cacheURL ] = modified; |
707 |
} |
708 |
} |
709 |
|
710 |
// if no content
|
711 |
if ( status === 204 || s.type === "HEAD" ) { |
712 |
statusText = "nocontent";
|
713 |
|
714 |
// if not modified
|
715 |
} else if ( status === 304 ) { |
716 |
statusText = "notmodified";
|
717 |
|
718 |
// If we have data, let's convert it
|
719 |
} else {
|
720 |
statusText = response.state; |
721 |
success = response.data; |
722 |
error = response.error; |
723 |
isSuccess = !error; |
724 |
} |
725 |
} else {
|
726 |
// We extract error from statusText
|
727 |
// then normalize statusText and status for non-aborts
|
728 |
error = statusText; |
729 |
if ( status || !statusText ) {
|
730 |
statusText = "error";
|
731 |
if ( status < 0 ) { |
732 |
status = 0;
|
733 |
} |
734 |
} |
735 |
} |
736 |
|
737 |
// Set data for the fake xhr object
|
738 |
jqXHR.status = status; |
739 |
jqXHR.statusText = ( nativeStatusText || statusText ) + "";
|
740 |
|
741 |
// Success/Error
|
742 |
if ( isSuccess ) {
|
743 |
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] ); |
744 |
} else {
|
745 |
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] ); |
746 |
} |
747 |
|
748 |
// Status-dependent callbacks
|
749 |
jqXHR.statusCode( statusCode ); |
750 |
statusCode = undefined;
|
751 |
|
752 |
if ( fireGlobals ) {
|
753 |
globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError", |
754 |
[ jqXHR, s, isSuccess ? success : error ] ); |
755 |
} |
756 |
|
757 |
// Complete
|
758 |
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] ); |
759 |
|
760 |
if ( fireGlobals ) {
|
761 |
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
|
762 |
// Handle the global AJAX counter
|
763 |
if ( !( --jQuery.active ) ) {
|
764 |
jQuery.event.trigger("ajaxStop");
|
765 |
} |
766 |
} |
767 |
} |
768 |
|
769 |
return jqXHR;
|
770 |
}, |
771 |
|
772 |
getJSON: function( url, data, callback ) { |
773 |
return jQuery.get( url, data, callback, "json" ); |
774 |
}, |
775 |
|
776 |
getScript: function( url, callback ) { |
777 |
return jQuery.get( url, undefined, callback, "script" ); |
778 |
} |
779 |
}); |
780 |
|
781 |
jQuery.each( [ "get", "post" ], function( i, method ) { |
782 |
jQuery[ method ] = function( url, data, callback, type ) {
|
783 |
// shift arguments if data argument was omitted
|
784 |
if ( jQuery.isFunction( data ) ) {
|
785 |
type = type || callback; |
786 |
callback = data; |
787 |
data = undefined;
|
788 |
} |
789 |
|
790 |
return jQuery.ajax({
|
791 |
url: url,
|
792 |
type: method,
|
793 |
dataType: type,
|
794 |
data: data,
|
795 |
success: callback
|
796 |
}); |
797 |
}; |
798 |
}); |
799 |
|
800 |
return jQuery;
|
801 |
}); |