I\'m trying to send a PUT
request on the unload
event, however the request is always cancelled.
Answers here says it\'s not possible:How to per
All you need to do is make the ajax call synchronous. That way the browser will wait for the response before closing the window/tab and it will not be cancelled.
$(window).unload(function(){
$.ajax({
type: 'PUT',
url: '/your_url.php',
async:false, //IMPORTANT, the call will be synchronous
data: {}
}).done(function(data) {
console.log('complete');
});
});