Forum Moderators: open
The Server side code is called when the Javascript is executed for the first time and the readystate is 1.
But when I am trying to hit it again, the server side code is not hit and the ready state is shown as 4.
I'm trying to hit the server side code everytime the AJAX code is executed.
Please find the code below:
function confirmExit() {
var request = false;
var uri = "test1.aspx";
alert("State:" + request.readystate);
if (window.ActiveXObject) // for IE
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) // for other browsers
{
request = new XMLHttpRequest();
}
request.open("GET",uri, true);
request.send(null);
}
Vikas
Your problem may be caused by browser caching. Try sending some anti-cache headers along with the request:
request.open("GET",uri, true);
request.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
request.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
request.setRequestHeader("Pragma", "no-cache");
request.send(null);