The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

I searched because I'm thinking this must have come up, but I cannot find it.

A few months back, I was trying to get AJAX to work and the send (request?) statement kept behaving as though it really wasn't contacting the server (other than the first time). I'm grateful for the response on this forum that suggested I add something different (e.g. a timestamp) to the send statement each time because the machine was thinking it had already handled an identical request and didn't bother to actually contact the server. IT WORKED. That appeared to be the problem.

I'm tesing with different browsers, and I just noticed that with Internet Explorer 7 (IE7) it is behaving as though the send is identical. It works with all other browsers, but not with IE7. Has anyone got any ideas ?

Thanks in advance.
Eric,
this is what I am using now

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.setRequestHeader("If-Modified-Since","Sat, 01 Jan 2000 00:00:00 GMT");
req.send();
}

And it fails to work at all.

Have you got a piece of code that works? I would be pleased to retrofit it into mine.

Thanks again for all your time.

Message was edited by:
blowfish
YO!

I just put the datestamp back into the send (because I saw firefox tell me in javascript console that I was short on parameters, and now it works with all the browsers (at least firefox, safari, and IE7) !

here's the code right now

if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");
//req.send();
d = new Date();
t = d.getTime();
thetimestring=t.toString(10);
req.send(thetimestring);
}

Thanks very much.

Message was edited by:
blowfish
Eric,
thanks. I'm really new at this and quite ignorant. Where would I put that statement in this code?


if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
d = new Date();
t = d.getTime();
thetimestring=t.toString(10);
req.send(thetimestring);
}

Thanks again.
I downloaded the code for chapter 2 (callbacktest.html) and it worked. so I modified it to do the function loadXMLDoc every 10 seconds. The script its calling (myscript) is checking a piece of data to see if it's changed. if it's changed, the script sends back a statement saying it's changed. if it's not, it says it's not.

this works fine with Mozilla browswers, I watch the output being displayed by callbacktest and it reports "no change" every 10 seconds. I reach over and change the data and callbacktest says "data has changed".

with Internet Explorer it's a different story. It never notices the data has changed. Not only that, it never notices if I change or delte myscript after the first call. Here are my assumptions:
1) IE uses ActiveXObject part of callbacktest and Mozilla uses XMLHttpRequest.
2) because when callbacktest is run with IE it just keeps reporting "no change", and acting as though it's stuck on it's first impression of the data, and cannot see the change, it never really calls myscript a second time. it's looking at some sort of cache. I got real confirmation of this when I sent up a new myscript to the server, and callbackttest under IE just kept right on acting and reporting as if it were calling the old script. I had to kill IE and restart it to get it to call the new script.

I'm wondering:
1) should I do some sort of "req.close" (if that's correct syntax) to flush things after each send.
2) should I NOT be instantiating a new req (request object) for each send but simply doing another send?
3) Have I got something set wrong in IE ?

Thanks for your time and suggestions.
I cannot thank you enough. I've got it working now, thanks to your suggestions.