473,396 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XmlHttpRequest cancelled when the page is unloaded

Hi!

What is the expected behaviour when you send an XmlHttpRequest just
before the page is about to unload? I'm sending a XmlHttpRequest on an
onClick event, and I can inspect that the request is sent and
responded in the network traffic, but my onReadyStateChange handler is
notified with an error.

It took me some time to deduce what the real problem was, and I think
my browser begins to tear down the XmlHttpRequest when the page is
about to unload. Therefore, the request is sent, but the browser
cancels before the response is processed and onReadyStateChange is
notified with an error.

I'm using Safari/KHTML.

I searched W3's draft specification,
http://www.w3.org/TR/XMLHttpRequest/
but could not find any answer.

Should the browser wait on XmlHttpRequest completion before the page
is unload? Or should the browser cancel pending XmlHttpRequests when
the page is about to unload?

Jan 29 '07 #1
3 7058
pe****@gmail.com wrote:
Hi!

What is the expected behaviour when you send an XmlHttpRequest just
before the page is about to unload? I'm sending a XmlHttpRequest on an
onClick event, and I can inspect that the request is sent and
responded in the network traffic, but my onReadyStateChange handler is
notified with an error.

It took me some time to deduce what the real problem was, and I think
my browser begins to tear down the XmlHttpRequest when the page is
about to unload. Therefore, the request is sent, but the browser
cancels before the response is processed and onReadyStateChange is
notified with an error.

I'm using Safari/KHTML.

I searched W3's draft specification,
http://www.w3.org/TR/XMLHttpRequest/
but could not find any answer.

Should the browser wait on XmlHttpRequest completion before the page
is unload? Or should the browser cancel pending XmlHttpRequests when
the page is about to unload?
From my experience (which does not include Safari), a user's navigation
requests will trump anything save for modal dialog boxes (alert, prompt,
etc). That means, no matter what your program is doing, it will be
halted in its tracks when the user navigates away.

HOWEVER, a synchronous Ajax request is "modal" in that it will stall
your script until it receives an answer back from the server. I don't
know if it will interfere with user navigation requests the way a
prompt/alert box will, but if you're desperate you might want to try
using a synchronous Ajax request instead of an asynchronous request.

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Jan 29 '07 #2
pcx99 wrote:
From my experience (which does not include Safari), a user's navigation
requests will trump anything save for modal dialog boxes (alert, prompt,
etc). That means, no matter what your program is doing, it will be
halted in its tracks when the user navigates away.

HOWEVER, a synchronous Ajax request is "modal" in that it will stall
your script until it receives an answer back from the server. I don't
know if it will interfere with user navigation requests the way a
prompt/alert box will, but if you're desperate you might want to try
using a synchronous Ajax request instead of an asynchronous request.
And no sooner do I write this than I stumble across an article which
tests this very thesis.

http://www.oreillynet.com/xml/blog/2..._browsers.html

Firefox will stall, opera and IE do not stall, and Firefox considers the
stall a bug, or defect, and is fixed in the nightly builds which means
the next release of Firefox will not stall waiting for synchronous requests.

The article was dated only yesterday so I do have a little excuse ;)

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Jan 30 '07 #3
Hi,

pcx99 wrote:
pcx99 wrote:
> From my experience (which does not include Safari), a user's
navigation requests will trump anything save for modal dialog boxes
(alert, prompt, etc). That means, no matter what your program is
doing, it will be halted in its tracks when the user navigates away.

HOWEVER, a synchronous Ajax request is "modal" in that it will stall
your script until it receives an answer back from the server. I
don't know if it will interfere with user navigation requests the way
a prompt/alert box will, but if you're desperate you might want to try
using a synchronous Ajax request instead of an asynchronous request.

And no sooner do I write this than I stumble across an article which
tests this very thesis.

http://www.oreillynet.com/xml/blog/2..._browsers.html
Firefox will stall, opera and IE do not stall, and Firefox considers the
stall a bug, or defect, and is fixed in the nightly builds which means
the next release of Firefox will not stall waiting for synchronous
requests.

The article was dated only yesterday so I do have a little excuse ;)
Careful here. The *browser* will not freeze, but the *current page* will
freeze. So actually, your first answer is totally correct IMHO, in that
a sync AJAX call behaves very much like an "alert", and the current
script execution is blocked until the response arrives (or until an
error occurs).

This is still a reason to recommend not using sync calls except in
special cases. Having the current page blocked for a noticeable time is
not user friendly, and can create unwanted side effects.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Jan 31 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: RCarter | last post by:
Hi, I have to write a web program (not a web site) and I was exploring all possibilities. When I found XMLHttpRequest I decided to use it. I'm interesting also in DOM, and I formuled this idea of...
4
by: Matt Sawyer | last post by:
I am attempting to use an API (CxApiOem.dll) that has a large number of defines and complicated structs. It's just too much hassle to attempt to use DLLImport to make the desired API calls. ...
5
by: jake | last post by:
I've seen many articles that claim the files in the App_Code directory are treated in the same way as aspx-files in ASP 1.1. Well, this does not seem to be the case, at least in Web Developer 2005...
42
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox...
1
by: mathewda | last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding me at the moment. I've wrote some code that will set up an XMLHttpRequest, it then makes a call to open and send and sets the...
5
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
4
by: sid | last post by:
Can someone tell me how to detect "Action Cancelled" page with out polling. I have a frame set and I want to make sure the other frame is displaying what it is supposed to without polling. For...
2
by: Gianluca | last post by:
Hi all, I developed a portal using Joomla 1.0.13 and Joomlajax (a plugin to implement Ajax in Joomla, based on Scriptaculous and Prototype) as core. I added some javascript code on index.php to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.