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?
It is not good Idea to display alert box for waiting response from ajax. Generally you can use alert box for message for confirmation of Leaving page after ajax response.
For avoiding use of alert you can call Ajax synchronously for example
if(window.XMLHttpRequest) xmlHttpObj=new XMLHttpRequest();
else xmlHttpObj=new ActiveXObject("Microsoft.XMLHTTP");
if(xmlHttpObj){
xmlHttpObj.onreadystatechange=function(){
if(xmlHttpObj.readyState==4 && xmlHttpObj.status == 200){
// your logic required
}
}
xmlHttpObj.open("GET", "your request url", false); // used false for synchronous call
xmlHttpObj.send(null);
}
else{
alert("AJAX not support");
}