I am attempting to invoke a service that updates data upon browser close or tab close. The issue I am facing is that the service call uses $http and is asynchronous, so I believe that the browser unload event is cancelling the call and closing the browser. I would like the browser to wait until I receive a response or an error for that service call.
I have attempted to call e.preventDefault() and e.stopPropagation() but they are not having any effect.
function releaseDocument(e) {
EventService.releaseDocument().then(function() {
window.close();
}, function() {
window.close();
});
}
$window.onbeforeunload = releaseDocument;
$window.onunload = releaseDocument;
Can someone please assist or suggest any alternatives to achieve the same goal?