From: Mike Duffy on
After reading up a bit on Ajax, decided to try out a simple test script.
It works with IE (8), but not FF (3.5.3). I might add support for other
browsers later using the try..catch techniques that are well-documented
elsewhere, but that would be pointless to try when I cannot correctly
write the absolute simplest example I could think of, which was to take
the jibbering example and then change it to point to my own server.

In effect, I was looking for a script to tell me the server time, because
their clock is always several minutes slow and I need to know how many
minutes I need to wait after uploading a file before my new documents get
treated as being more recent than the ones in the various server cache
proxies.

When I run it with FF, it does not look like the callback is ever
executed. It just sits there. I have looked at dozens of ajax tutorial
sites, and they all boil down to the following code when you take away
the support for old browsers.

And I am using the index page of my website as the Ajax target, because
if I use a 3rd party site, IE gives me the warning about mixing secure /
insecure items.

<html lang="en">
<head>
<title>Test Server Time</title>

</head>

<body onLoad="test()">

<script type="text/javascript">
function test() {
var xmlhttp = new XMLHttpRequest();

xmlhttp.open("HEAD", "http://pages.videotron.com/duffym/index.htm",
false);

xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
document.write('Time at server: ' + xmlhttp.getResponseHeader('Date'))
};

}
xmlhttp.send(null);
}
</script>

</body>
</html>
From: Thomas 'PointedEars' Lahn on
David Mark wrote:

> On Dec 22, 11:57 pm, Mike Duffy <resp...(a)invalid.invalid> wrote:
>> function test() {
>> var xmlhttp = new XMLHttpRequest();
>>
>> // true = async; false = sync
>> xmlhttp.open("HEAD", "http://pages.videotron.com/duffym/index.htm",
>> true);
>>
>> xmlhttp.onreadystatechange=function() {
>> if (xmlhttp.readyState==4) {
>> logMessage("Time at server: " + xmlhttp.getResponseHeader('Date'))
>> };
>
> Always set onreadystatechange before opening.

Nonsense. For compatibility, it needs to come afterwards. At least older
Geckos reset the property value on open().


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
From: David Mark on
On Dec 23, 7:40 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> David Mark wrote:
> > On Dec 22, 11:57 pm, Mike Duffy <resp...(a)invalid.invalid> wrote:
> >> function test() {
> >> var xmlhttp = new XMLHttpRequest();
>
> >> // true = async; false = sync
> >> xmlhttp.open("HEAD", "http://pages.videotron.com/duffym/index.htm",
> >> true);
>
> >> xmlhttp.onreadystatechange=function() {
> >> if (xmlhttp.readyState==4) {
> >> logMessage("Time at server: " + xmlhttp.getResponseHeader('Date'))
> >> };
>
> > Always set onreadystatechange before opening.
>
> Nonsense.  For compatibility, it needs to come afterwards.  At least older
> Geckos reset the property value on open().

Yes, I had that backwards. Thanks.
From: Mike Duffy on
Thomas 'PointedEars' Lahn <PointedEars(a)web.de> wrote in
news:3803771.bqXVLH7GnM(a)PointedEars.de:

> David Mark wrote:
>
>> On Dec 22, 11:57 pm, Mike Duffy <resp...(a)invalid.invalid> wrote:
>>> function test() {
>>> var xmlhttp = new XMLHttpRequest();
>>>
>>> // true = async; false = sync
>>> xmlhttp.open("HEAD", "http://pages.videotron.com/duffym/index.htm",
>>> true);
>>>
>>> xmlhttp.onreadystatechange=function() {
>>> if (xmlhttp.readyState==4) {
>>> logMessage("Time at server: " + xmlhttp.getResponseHeader('Date'))
>>> };
>>
>> Always set onreadystatechange before opening.
>
> Nonsense. For compatibility, it needs to come afterwards. At least
> older Geckos reset the property value on open().
>
>
> PointedEars

Changing the order as he suggested did fix my problem. (Thank you David!)

It did not, however seem to work perfectly. Each "refresh" in IE added a
line with the new updated time. However, in FF the identical time was
appended with each refresh.

I fixed that by appending:

"?en&rt=" + Math.random()

to the url. Out of curiousity, I wonder if the problem had anything to do
with the fact that my WSP always run the clock a few minutes slow.

In any case, at least I have a "working" function I can build on.
From: David Mark on
On Dec 23, 8:25 pm, Mike Duffy <resp...(a)invalid.invalid> wrote:
> Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote innews:3803771.bqXVLH7GnM(a)PointedEars.de:
>
>
>
> > David Mark wrote:
>
> >> On Dec 22, 11:57 pm, Mike Duffy <resp...(a)invalid.invalid> wrote:
> >>> function test() {
> >>> var xmlhttp = new XMLHttpRequest();
>
> >>> // true = async; false = sync
> >>> xmlhttp.open("HEAD", "http://pages.videotron.com/duffym/index.htm",
> >>> true);
>
> >>> xmlhttp.onreadystatechange=function() {
> >>> if (xmlhttp.readyState==4) {
> >>> logMessage("Time at server: " + xmlhttp.getResponseHeader('Date'))
> >>> };
>
> >> Always set onreadystatechange before opening.
>
> > Nonsense.  For compatibility, it needs to come afterwards.  At least
> > older Geckos reset the property value on open().
>
> > PointedEars
>
> Changing the order as he suggested did fix my problem. (Thank you David!)

I told you _wrong_ (it must have been a long day). Put the order back
the way it was.

Something else must be wrong and I don't see what it is offhand. Your
code works in the Firebug console, except that logMessage bombs
looking for your form.