I'm Trying to call a ajax method on browser close/ site leaving situation.
I already tried many methods such as "beforeunload" as you can see below, but every of them just called when the browser close & any redirection(even redirects to other pages of current website)
Actually i need a method to detect if the user is leaving the whole web site or closing the browser, it's important to calling my ajax before user leaving the site(Not just the current page). it means i do not want to call that method when the user is hanging around in my web site. I just want it when user is leaving whole the site.
$(window).on('beforeunload', function () {
var params = { pId: -1, Qty: -1, StatusQuo: true };
$.ajax({
type: 'POST',
cache: false,
url: '/api/SiteServices.asmx/UserBasketAction',
data: JSON.stringify(params),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result) {
if (result.d == true)
alert("test");
return false;
},
error: function (result) { alert(result.status + ' ' + result.statusText) },
complete: function () {
alert("sdasdad");
}
});
});
for more description i want to redeem some reservation in basket from inventory just if user is leaving the reserves in basket & wants to leave the site.