Bug Tracker

Opened 6 years ago

Closed 6 years ago

#12824 closed bug (notabug)

Ajax fires abort onunload event, even when using XMLHTTP (IE only)

Reported by: eyaleyal2001@… Owned by: eyaleyal2001@…
Priority: undecided Milestone: None
Component: ajax Version: 1.8.2
Keywords: Cc: jaubourg
Blocked by: Blocking:

Description

On IE8/9, When using Ajax call when OnUnload event fires, the ajax call is aborted immediately. While looking at the jQuery source, i found out that there is a place when you want to release the IE resources when using ActiveX : when setting the xhrOnUnloadAbort var.

On the other hand, when setting the xhr object for IE, there is a function that returns the standard XHR while calling createStandardXHR(). (in case the isLocal param is false). (I belive the logic was that the activeX will always work when available, but it actually using the standard XMLHTTP)

I think it is kind of logic conflict...

I've tried to look for a way to change the xhrOnUnloadAbort, but there is no access for it. And i thing maybe there should be one?

My final solution in the code is to define xhrOnUnloadAbort when considering the isLocal var as well:

xhrOnUnloadAbort = this.isLocal && window.ActiveXObject ? function() {

Abort all pending requests for ( var key in xhrCallbacks ) {

xhrCallbacks[ key ]( 0, 1 );

}

} : false

Creating an example for it is difficult, because i discovered it on a server side error (probably when a connection was opened and aborted immediately with no data). So in FireFox and Chrome it works great and the connection is not aborted. I didn't find any information about resources abuse of IE when using XMHHTTP.

Change History (6)

comment:1 Changed 6 years ago by timmywil

Cc: jaubourg added
Component: unfiledajax

comment:2 Changed 6 years ago by dmethvin

jaubourg, can you weigh in on this ticket?

comment:3 Changed 6 years ago by jaubourg

On IE8/9, When using Ajax call when OnUnload event fires, the ajax call is aborted immediately.

Please, tell me you made a synchronous request. If you made an asynchronous one, you're not guaranteed it will finish before the browser navigates to another page anyway.

comment:4 Changed 6 years ago by dmethvin

Owner: set to eyaleyal2001@…
Status: newpending

comment:5 in reply to:  3 Changed 6 years ago by anonymous

Replying to jaubourg:

On IE8/9, When using Ajax call when OnUnload event fires, the ajax call is aborted immediately.

Please, tell me you made a synchronous request. If you made an asynchronous one, you're not guaranteed it will finish before the browser navigates to another page anyway.

Hi, I know that using a synchronous request will work. But, the asynchronous requests used to work as well when using XMLHTTP directly before moving to JQuery to manage my ajax requests. Firefox and Chrome work perfect with the same code i am running asynchronous. It doesn't change the issue of non logical dealing of aborting the requests. one u do to IE, even though no ActiveX object had been created and used.

comment:6 Changed 6 years ago by jaubourg

Resolution: notabug
Status: pendingclosed

I assume you're talking about requests issued from an onunload handler. Because, if you're talking about any request in your page (that is requests that are not issued in an onunload handler), I find your statement about requests never being aborted in Chrome and FF very hard to believe. Hence why I assume the former. Some code sample / test case would have helped clarify this much better than an attempted "fix" inside jQuery.

Anyway, glad to know you know about synchronous requests working. Where is it mentionned in the bug report? :P

Firefox and Chrome do not work "perfect" with asynchronous requests. It just so happens your network is good enough, your server close enough or your computer slow enough for the request to be sent before the page is actually unloaded. That's not at all guaranteed though. Any network congestion or just having a faster computer will abort the request early, just like jQuery does in IE, and the data will never reach the server. Even requests with no data are not guaranteed to reach the server!

You must use synchronous requests in an onunload handler. See the top response here for the full rationale.

Last edited 6 years ago by jaubourg (previous) (diff)
Note: See TracTickets for help on using tickets.