Reputation: 815
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!
Upvotes: 3
Views: 1553
Reputation: 617
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.
Upvotes: 1