Skip to main content

Bug Tracker

Side navigation

#12824 closed bug (notabug)

Opened November 01, 2012 01:02PM UTC

Closed November 23, 2012 12:10PM UTC

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

Reported by: eyaleyal2001@yahoo.com Owned by: eyaleyal2001@yahoo.com
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.

Attachments (0)
Change History (6)

Changed November 01, 2012 02:28PM UTC by timmywil comment:1

cc: → jaubourg
component: unfiledajax

Changed November 21, 2012 10:04PM UTC by dmethvin comment:2

jaubourg, can you weigh in on this ticket?

Changed November 22, 2012 04:10PM UTC by jaubourg comment:3

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.

Changed November 22, 2012 05:25PM UTC by dmethvin comment:4

owner: → eyaleyal2001@yahoo.com
status: newpending

Changed November 23, 2012 08:57AM UTC by anonymous comment:5

Replying to [comment:3 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.

Changed November 23, 2012 12:10PM UTC by jaubourg comment:6

_comment0: ''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 clarified 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 [http://stackoverflow.com/questions/3584288/can-the-unload-event-be-used-to-reliably-fire-ajax-request here] for the full rationale.1353672740989474
_comment1: ''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 clarified 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 [http://stackoverflow.com/questions/3584288/can-the-unload-event-be-used-to-reliably-fire-ajax-request here] for the full rationale.1353672795716433
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.