Hi I use javascript to save information after page going to be close or navigate to another page.My problem is when I call webservice in window.onbeforeunload it is not going to fire and I dont get result. But If I put alert at the end of function webservice going to fire and I get result.I don’t want to use alert at all .Is there any way.my code is as follows:
window.onbeforeunload = InitializeService;
function InitializeService() {
if (window.XMLHttpRequest) {
var url = "http://localhost:54329/WebServices/PageUnloadCall.asmx?op=Page_Unload";
myReq.onreadystatechange = checkStatus1;
myReq.open("GET", url, true); // true indicates asynchronous request
myReq.send();
// alert("Your Call Record Has Been Saved!");
}
}
function checkStatus1() {
if (myReq.readyState == 4) // Completed operation
{
myReq.open("POST", "http://localhost:54329/WebServices/PageUnloadCall.asmx/Page_Unload", false);
myReq.send();
}
}
As you can see in function InitializeService ,I dont want to use Alert there but if I dont I dont get result.
The alert is allowing the async call to finish allowing the response. Change:
to: