I have the follow code:
window.onbeforeunload = function() {
$.post(
'script/ratings.php',
{
data: dataToServer,
slider: slider_position_value,
article: ARTICLE_NAME
},
function(data) {
});
};
that works perfectly in IE and Mozilla. Of oourse, I know about the bug in Chrome due to this event doesn’t appear. I need recipe to catch this event and make POST-request into it.
Thanks.
The
beforeunloadevent does work in Chrome. However, upon page leave, all requests, including AJAX, are cancelled.To get your current code to work, use a synchronous request, by adding
async:falseto thejQuery.ajaxset-up. This blocks the UI till a response is received, and is not recommended.