Running a GET request before going to a page - Javascript

if the GET request is made as follows

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

and the page is left until the GET request is completed ,

will the target server process the request ? Or will it somehow disappear?


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

It would be very helpful if someone could help me.

+6
javascript ajax javascript-events get onbeforeunload
source share
2 answers

If it is an asynchronous request, the server can 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 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 passes and it will return a response (so that in this case, processing will be guaranteed). However, this means that your browser will be blocked until this request is completed, which may be undesirable.

+1
source share

In most cases, yes, but it depends on the web application server. Some may find a disconnect and stop requesting.

+1
source share

All Articles