views:

83

answers:

2

Hi folks,

if a GET request is made as follows

$(window).bind('beforeunload', function() {
    // GET request
});

and the page is abandoned before the GET request is completed,

will the destination server still process the request? Or will it somehow vanish?


I would like to send a server data on "beforeunload" firing, but without stealing useless ms from the user.

It would be very useful if someone could help me.

+1  A: 

In most cases yes, but it depends on the web application server. Some can detect the disconnect and stop with the request.

Joe Martinez
Thanks for the reply! =) I'm using python, and looking into various networking libraries.
RadiantHex
+1  A: 

If it is an asynchronous request then the server may process it (if it receives the request) but I don't know if you can guarantee that the request will go through before the page is unloaded or if it will be processed - this may depend on the actual web server (someone else may have more information). If you make a synchronous request, the page will wait until the request goes through and it gets back a response (so in this case, processing is guaranteed). However, this means that your browser will be locked up until that request completes, which may not be desirable.

Vivin Paliath
I agree, I wouldn't do it for anything that needs to rely on the request going through.
Joe Martinez
@Joe yeah, in general this is not very reliable.
Vivin Paliath
@Joe @Vivin thanks for the replies! =) There must be a way of achieving more than 90% success ratio?
RadiantHex