3 var // Next fake timer id
4 xhrPollingId = jQuery.now(),
13 xhrUnloadAbortInstalled;
16 jQuery.ajax.transport( function( s , determineDataType ) {
18 // Cross domain only allowed if supported through XMLHttpRequest
19 if ( ! s.crossDomain || jQuery.support.cors ) {
25 send: function(headers, complete) {
27 // #5280: we need to abort on unload or IE will keep connections alive
28 if ( ! xhrUnloadAbortInstalled ) {
30 xhrUnloadAbortInstalled = 1;
32 jQuery(window).bind( "unload" , function() {
34 // Abort all pending requests
35 jQuery.each(xhrs, function(_, xhr) {
36 if ( xhr.onreadystatechange ) {
37 xhr.onreadystatechange( 1 );
45 var xhr = xhrPool.pop() || s.xhr(),
49 // Passing null username, generates a login popup on Opera (#2865)
51 xhr.open(s.type, s.url, s.async, s.username, s.password);
53 xhr.open(s.type, s.url, s.async);
56 // Requested-With header
57 // Not set for crossDomain requests with no content
58 // (see why at http://trac.dojotoolkit.org/ticket/9486)
59 // Won't change header if already provided
60 if ( ! ( s.crossDomain && ! s.hasContent ) && ! headers["x-requested-with"] ) {
61 headers["x-requested-with"] = "XMLHttpRequest";
64 // Need an extra try/catch for cross domain requests in Firefox 3
67 jQuery.each(headers, function(key,value) {
68 xhr.setRequestHeader(key,value);
73 // Do send the request
75 xhr.send( ( s.hasContent && s.data ) || null );
77 // Store back into pool
79 complete(0, "error", "" + e);
84 callback = function( isAbort ) {
86 // Was never called and is aborted or complete
87 if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
92 // Do not keep as active anymore
93 // and store back into pool
95 xhr.onreadystatechange = jQuery.noop;
96 delete xhrs[ handle ];
104 // Abort it manually if needed
105 if ( xhr.readyState !== 4 ) {
111 var status = xhr.status,
114 responseHeaders = xhr.getAllResponseHeaders();
116 try { // Firefox throws an exception when accessing statusText for faulty cross-domain requests
118 statusText = xhr.statusText;
122 statusText = ""; // We normalize with Webkit giving an empty statusText
126 // Filter status for non standard behaviours
127 // (so many they seem to be the actual "standard")
129 // Opera returns 0 when it should be 304
130 // Webkit returns 0 for failing cross-domain no matter the real status
133 ! s.crossDomain || statusText ? // Webkit, Firefox: filter out faulty cross-domain requests
135 responseHeaders ? // Opera: filter out real aborts #6060
141 302 // We assume 302 but could be anything cross-domain related
145 status == 1223 ? // IE sometimes returns 1223 when it should be 204 (see #1450)
151 // Guess response & update dataType accordingly
155 xhr.getResponseHeader("content-type"),
160 complete(status,statusText,response,responseHeaders);
165 // if we're in sync mode
166 // or it's in cache and has been retrieved directly (IE6 & IE7)
167 // we need to manually fire the callback
168 if ( ! s.async || xhr.readyState === 4 ) {
174 // Listener is externalized to handle abort on unload
175 handle = xhrPollingId++;
176 xhrs[ handle ] = xhr;
177 xhr.onreadystatechange = function() {