In my web app, I need to send the latest data the user has changed before they leave the page.
I call up a function like this when the page unloads:
window.onbeforeunload=sendData;
That's what's inside the function called
function sendData(){
var xhr = new XMLHttpRequest;
var storage = container;
xhr.open("POST","save.php",false);
xhr.send("information="+container);
}
My questions:
What is more right: Using async or sync to make send the requests before the user closes the page?
Is it possible to make the requests smaller? I only send variables containing up to two characters and the whole request takes 171 bytes!
It's necessary to use a synchronous request, otherwise, the data is not transmitted in IE10 and IE11, see Unload event in IE10, no form data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With