Is it possible for onbeforeunload()
function to wait for ajax result and move to a jsp based on the resultvalue or atleast show a message before unloading?
This is my strategy and works for me:
_number_of_active_ajax ++;
$.ajax({
url: REQUEST_URL,
timeout: 3000
})
.always(function() {
_number_of_active_ajax --;
});
window.onbeforeunload = function() {
if(_number_of_active_debounce > 0 || _number_of_active_ajax > 0)
return "Your question";
}
}
It will show a message to use if the page has an active request.