Help! Subsequent Get Requests using xmlhttp return identical results

T

tlang

Has anybody experienced the following? The below Get request is called
when a button on the page is clicked:

function GetTranscript(){
var oSend = new ActiveXObject("Msxml2.XMLHTTP.3.0");
oSend.Open("GET", "transcript.aspx", true);
oSend.onreadystatechange = function() {
if (oSend.readyState == 4) {
alert(oSend.responseText);
}
}
oSend.send(null);
oSend = null;
return false;
}

The page transcript.aspx returns the current date, i.e.
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Response.Write(System.DateTime.Now.ToLongTimeString());
Response.End();
}

The first call through xmlhttp works great. Subsequent calls return
the same exact time.

HELP! Dont know what else to do.

dead in the water,
Tom
 
R

Randy Webb

tlang said:
Has anybody experienced the following? The below Get request is called
when a button on the page is clicked:

function GetTranscript(){
var oSend = new ActiveXObject("Msxml2.XMLHTTP.3.0");

It may be that it's getting the page from a cache somewhere, but never
experienced this problem. What you can try doing is making the file name
unique so that it forces it from the server:

myFile = "transcript.aspx?" + new Date().getTime();
oSend.Open("GET", "transcript.aspx", true);

oSend.Open("GET",myFile,true);

It may work, it may not, but worth trying.
 
T

tlang

Thanks Randy. This worked:
<script language="javascript">
function GetTranscript(){
var oSend = new ActiveXObject("Msxml2.XMLHTTP.3.0");
myFile = "transcript.aspx?time=" + new Date().getTime();
oSend.Open("GET", myFile, true);
oSend.onreadystatechange = function() {
if (oSend.readyState == 4) {
alert(oSend.responseText);
oSend = null;
}
}
oSend.send(null);
return false;
}
</script>

Not sure why the output of the aspx file was cached. I thought the
point of aspx files is that their contents is dynamic. I would think
making it static would be an explicit property setting. I'll try to
find out more info on that.

Tom
 
K

kdarling

Not sure why the output of the aspx file was cached. I thought
the point of aspx files is that their contents is dynamic.

What you saw is normal.

Page contents can be dynamic, but unless you specify a different URL
(or use a POST instead of a GET), the browser will use the page with
the same URL from cache. (Assuming you haven't used an expiration date
or other methods to prevent that.)

We have an internal site that makes extensive use of cached files to
speed up usage over dialup. To force a download, we use the method as
was suggested... adding the date to create a new version parameter.

Kev
 
D

Diego Vilar

Randy is right... transcript.aspx is being cached.... I've had the same
problem, and it can be quickly solved just by sending no-cache request
headers... For IE, the following alone will do it:

oSend.setRequestHeader("If-Modified-Since","Wed, 15 Nov 1995 04:58:08
GMT");

Don't know for other browsers, but try these:

oSend.setRequestHeader("Expires", "Wed, 15 Nov 1995 04:58:08 GMT");
oSend.setRequestHeader("Last-Modified", "Wed, 15 Nov 1995 04:58:08
GMT");
oSend.setRequestHeader("Cache-Control", "no-cache, must-revalidate");
oSend.setRequestHeader("Pragma", "no-cache");

Let us know if it worked..

[ ]'s
Diego
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top