Forum Moderators: open

Message Too Old, No Replies

Problem in hitting the server code second time when readystate = 4

Ajax, Readystate

         

vikasbinani

1:34 pm on Jul 17, 2006 (gmt 0)

10+ Year Member



I am writing a Javascript (AJAX) to hit a server side code.

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

RonPK

1:49 pm on Jul 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello Vikas, welcome to WebmasterWorld!

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);