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>
Synchronous requests are always a bad idea.
https://developer.mozilla.org/en/XmlHttpRequest#open%28%29
>
> xmlhttp.onreadystatechange=function() {
> if (xmlhttp.readyState==4) {
> document.write('Time at server: ' + xmlhttp.getResponseHeader('Date'))
Calling document.write on load is also a bad idea as it will wipe out
the previously loaded document.
> };
>
> }
> xmlhttp.send(null);}
>
> </script>
>
> </body>
> </html>
> Synchronous requests are always a bad idea.
I tried it both ways; the result is the same. I presumed sync would be
less trouble.
> Calling document.write on load is also a bad idea as it will wipe out
> the previously loaded document.
That's a good point. I was doing it just to avoid the neccessity of
constantly dismissing alert boxes while I was trying out various things.
I have replaced it with a textbox and switched to using asynchronous
calls to be more in line with the common usage of the XMLHttpRequest
object. It still works okay with IE8, but not with FF 3.5.3.
Here is the new code; it can be reached on-line at
http://pages.videotron.com/duffym/t.htm
<html lang="en">
<head>
<title>Test Server Time</title>
</head>
<body onLoad="test()">
<script type="text/javascript">
function logMessage(message) {
var dtext = document.forms.debug.debugtext.value;
document.forms.debug.debugtext.value = dtext + message + '\n';
return;
}
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'))
};
}
xmlhttp.send(null);
}
</script>
<p id="debug"><form name="debug">
<textarea name="debugtext" title="Debug" rows="10" cols="50" wrap="true">
</textarea></form></p>
</body>
</html>
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
Yes, I had that backwards. Thanks.
> David Mark wrote:
>
>> On Dec 22, 11:57 pm, Mike Duffy <resp...@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.
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.
> 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.
? I do not doubt you, but that was not my problem, FF just never did
anything. Actually, it did log the message one time but would never do it
again. The error console remained empty. On another occaision, I did see
error text appear in the console spontaneously a few minutes later. I was
trying various things, and as you may gather sometimes get mixed up about
what I have put in the file or javascript library. This is one of those
things I cannot debug offline because of the protocol / domain traversal
problem. (i.e file://C:/My Documents/... vs. http://videotron...)
Also, it might have something to do with the server time being so retarded.
> 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.
? I do not doubt you, but that was not my problem, FF just never did
In FF go to about:config and change
security.fileuri.strict_origin_policy to false.
>
> Also, it might have something to do with the server time being so retarded.
What sort of time is retarded?
>
> What sort of time is retarded?
>
The server I was tring to get the time from (my web service provider
"videotron") always has their clock set several minutes in the past.
I wanted to display exacty how much retarded it is, because that is how
long I need to wait after uploading a new document before it will pass
through web cache proxy servers. These are used, for example, by Google as
the source for a web page when you request a translation via url.
>
> What sort of time is retarded?
>
The server I was tring to get the time from (my web service provider
> On Dec 23, 11:36�pm, Mike Duffy <resp...@invalid.invalid> wrote:
>> David Mark <dmark.cins...@gmail.com> wrote
>
> In FF go to about:config and change
> security.fileuri.strict_origin_policy to false.
1) My apologies to all for the recent double-posting of my messages. AIEO
via Xnews was showing "Done. Waiting for confirmation." indefinitely.
Without the "Confirmation" I cannot resist the compulsion to post again,
despite the fact that it will usually end up making me look compulsive.
2) Thanks again David. As you may see, I have successfully added clocks to
all my web pages to show server time and local time.
http://pages.videotron.com/duffym/
3) Re your point above about security policies, thanks, I might use this on
a private area of my web site to get the correct time from a government
time server instead of from the local machine. But since this configuration
is not the installed default, I cannot assume that web visitors will have
this option (or the similar IE option) enabled.
But that brings up another question: How does Google implement an Ajax API
(such as the translation one I use extensively) to work without the warning
messages? They "google.com" are, in fact, receiving XML HTTP requests from
everyone all over the place. Most of these users use default security
settings. They are not bothered by those security warning messages.
The google code is obfuscted, I do not need to know THAT much how they do
it. I looked up (on the web) how to do this sort of thing in general, and
there are workarounds, but they all involve setting up a proxy on the end-
user's ISP system.
Do any of you know how they do it?
How do you get that to work for David and not for me?
>http://pages.videotron.com/duffym/
Putting the US flag first and the others in what looks like alphabetical
order of English form of language name is politically incorrect. The
flags should be in alphabetical order of the language currently being
shown, and the correct flag for English is of course the Cross of St
George. Latin & Esperanto seem to be missing.
The astro page has NaNs.
The puns page does not translate well.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
NP.
>
> 2) Thanks again David. As you may see, I have successfully added clocks to
> all my web pages to show server time and local time.
>
> http://pages.videotron.com/duffym/
I'll check it out when I get a chance...
>
> 3) Re your point above about security policies, thanks, I might use this on
> a private area of my web site to get the correct time from a government
> time server instead of from the local machine. But since this configuration
> is not the installed default, I cannot assume that web visitors will have
> this option (or the similar IE option) enabled.
The suggestion was just for local testing.
>
> But that brings up another question: How does Google implement an Ajax API
> (such as the translation one I use extensively) to work without the warning
> messages? They "google.com" are, in fact, receiving XML HTTP requests from
> everyone all over the place. Most of these users use default security
> settings. They are not bothered by those security warning messages.
I'll have to look at it.
>
> The google code is obfuscted, I do not need to know THAT much how they do
> it. I looked up (on the web) how to do this sort of thing in general, and
> there are workarounds, but they all involve setting up a proxy on the end-
> user's ISP system.
>
> Do any of you know how they do it?
Not sure until I look at it.
> Not sure until I look at it.
If you're curious. But like I said, it is not important for me. I have what
I want. They *might* be using the 1x1 invisible iframe trick to pass data
across domains. Thanks again.
> How do you get that to work for David and not for me?
>
>>http://pages.videotron.com/duffym/
Are you saying that the clocks (local & server) do not work for you? I
have not yet added the support for old (IE6 & <) browsers. Which browser
are you using?
> Putting the US flag first and the others in what looks like
> alphabetical order of English form of language name is politically
> incorrect.
They are in alphabetic order of the drop-down list on the Google
"translate text" page, which is, I believe, exactly as you say it looks
like. English has been pushed to the start in order to reduce the
complexity of debugging.
> The flags should be in alphabetical order of the language
> currently being shown,
Probably if I were hosting the UN web site I would do as you say, but
that seems to me to add complexity that does really add value to the
product worthy of the effort nor the risk of unforseen complications. To
be fair, I suppose I should use the alphabetic order of the 2 char iso
language code, and put English (en) in it's proper place between Greek
(el) and Spanish (es). The next time I find myself working on that part
of my javascript include file I will do exactly that.
> ... the correct flag for English is of course
> the Cross of St George.
I did actually consider this. But many international users would not make
the connection. As far as that goes, the UK flag is more widely used on
the web to denote the English language. But since my web-site is written
in Quebec English, it makes more sense to use the American flag.
There is a certain body of opinion that holds that flags should not be
used at all for language selection. The problem of choosing which country
flag to use for Swahili was reduced (for me) to picking the country with
the largest number of Swahili speakers. The Indian flag is an obvious
choice for Hindi written in the Devanagari script, but what will I do
when other uniquely Indian languages become supported? I used the Chinese
flag twice, but I cannot forsee doing this for all 400 Indian languages.
And did you recognize the flag I used for Yiddish?
> Latin & Esperanto seem to be missing.
As soon as Google supports them, I will add them. And I cannot for the
life of me guess what flags I will use.
> The astro page has NaNs.
In the planetary positions, or in the tide (gravity gradient)
calculation? Everything has always worked okay for me. I would appreciate
details on the errors you encountered.
> The puns page does not translate well.
If you thinks that's bad, check out my poetry!
> 2) Thanks again David. As you may see, I have successfully added clocks to
> all my web pages to show server time and local time.
>
> http://pages.videotron.com/duffym/
Your time is out by one hour. The southern half of the planet is in daylight
saving time right now.
Oh no we're not! At least those of us not living in sunshine-challenged
States anyway :-)
Cheers Richard Maher
>
>
> Putting the US flag first and the others in what looks like alphabetical
> order of English form of language name is politically incorrect. The
> flags should be in alphabetical order of the language currently being
> shown, and the correct flag for English is of course the Cross of St
> George. Latin & Esperanto seem to be missing.
Using flags for languages is incorrect as:
Some languages would need to point to many flags, and
most flags should point to more languages than one.
Even "political correct" has a different meaning for near every flag.
Why not stick to the compromize of wikipedia?
The translations used are laughably incorrect,
and often are nnot understandasble to a native speaker
without consulting the English version.
Does this have anything to do with Javascript?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
I see no clocks with Firefox 3.0.15, IE, Chrome, Opera, Safari. You did
write "I have successfully added clocks to all my web pages to show
server time and local time.", so I only looked at some pages.
>> Putting the US flag first and the others in what looks like
>> alphabetical order of English form of language name is politically
>> incorrect.
>
>They are in alphabetic order of the drop-down list on the Google
>"translate text" page, which is, I believe, exactly as you say it looks
>like. English has been pushed to the start in order to reduce the
>complexity of debugging.
>
>
>> The flags should be in alphabetical order of the language
>> currently being shown,
>
>Probably if I were hosting the UN web site I would do as you say, but
>that seems to me to add complexity that does really add value to the
>product worthy of the effort nor the risk of unforseen complications. To
>be fair, I suppose I should use the alphabetic order of the 2 char iso
>language code, and put English (en) in it's proper place between Greek
>(el) and Spanish (es). The next time I find myself working on that part
>of my javascript include file I will do exactly that.
>
>
>> ... the correct flag for English is of course
>> the Cross of St George.
>
>I did actually consider this. But many international users would not make
>the connection. As far as that goes, the UK flag is more widely used on
>the web to denote the English language. But since my web-site is written
>in Quebec English, it makes more sense to use the American flag.
You should be able to use both. But Wales, for which you have a flag,
is part of the UK. England is the only major part of the UK which has
no surviving active indigenous language other than English. But I think
you'd be hard pressed to find anyone (except maybe in Patagonia) who
would prefer Google's Welsh to your quasi-American English.
Take a look at my home page, via sig., which gives that translation
facility more economically.
>There is a certain body of opinion that holds that flags should not be
>used at all for language selection. The problem of choosing which country
>flag to use for Swahili was reduced (for me) to picking the country with
>the largest number of Swahili speakers. The Indian flag is an obvious
>choice for Hindi written in the Devanagari script, but what will I do
>when other uniquely Indian languages become supported? I used the Chinese
>flag twice, but I cannot forsee doing this for all 400 Indian languages.
>And did you recognize the flag I used for Yiddish?
>
>
>> Latin & Esperanto seem to be missing.
>As soon as Google supports them, I will add them. And I cannot for the
>life of me guess what flags I will use.
For Latin, a bust of Caesar should be recognisable; and Zamenhof looks
quite different. But the Wiki Zamenhof article shows what is presumably
an Esperanto flag, confirmed by the Esperanto article. The Rome article
shows a flag, which could be used - or an SPQR logo.
>> The astro page has NaNs.
>In the planetary positions, or in the tide (gravity gradient)
>calculation? Everything has always worked okay for me. I would appreciate
>details on the errors you encountered.
In the text, e.g. "Currently, the Moon is NaN % illuminated."
Obviously, a lot is not shown.
MSIE8 raises errors such as
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;
Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR
3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR
3.5.30729; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)
Timestamp: Mon, 28 Dec 2009 20:42:07 UTC
Message: 'google.loader.ClientLocation.latitude' is null or not an
object
Line: 36
Char: 1
Code: 0
URI: http://pages.videotron.com/duffym/astro.htm
Perhaps you are expecting readers to have installed something?
Maybe
uLat = google.loader.ClientLocation.latitude;
returns "undefined", which then should be tested for (Google has not
been told my latitude).
I've now quickly looked at the code. Perhaps HTML should show a
conspicuous area containing "If you can read this when loading is
finished, something is not working", and either replace it with results
or hide it.
For function jd(obs,actual) in astro.htm, you should be able to use
something *like*
new Date(obs.year, obs.month-1, obs.day) / 864e5 + constant
perhaps with a Date.UTC() inside.
You can use now.getFullYear instead of function getFullYear(now), or, if
you want to use only getYear, see :
function getFY(D) { var YE // needs full test in all browsers
YE = 1970 + Math.round(D.getTime() / 31556952000) // s per Greg yr
return YE + (D.getYear()-YE)%100 }
in <URL:http://www.merlyn.demon.co.uk/js-date0.htm#gFY>, in which
31556952000 only has to be roughly right (YE can be decades in error
without affecting the answer).
>> The puns page does not translate well.
>
>If you thinks that's bad, check out my poetry!
Unreadable in English, because of the colour and size.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
> >Probably if I were hosting the UN web site I would do as you say, but
> >that seems to me to add complexity that does really add value to the
> >product worthy of the effort nor the risk of unforseen complications. To
> >be fair, I suppose I should use the alphabetic order of the 2 char iso
> >language code, and put English (en) in it's proper place between Greek
> >(el) and Spanish (es). The next time I find myself working on that part
> >of my javascript include file I will do exactly that.
>
> >> ... the correct flag for English is of course
> >> the Cross of St George.
>
> >I did actually consider this. But many international users would not make
> >the connection. As far as that goes, the UK flag is more widely used on
> >the web to denote the English language. But since my web-site is written
> >in Quebec English, it makes more sense to use the American flag.
>
> You should be able to use both. But Wales, for which you have a flag,
> is part of the UK. England is the only major part of the UK which has
> no surviving active indigenous language other than English.
I've heard about the Northumbrian (Tyneside region of England) dialect
called 'Geordie'.
Eeeh man, ahm gannin te the booza.
--
JR
>> >> ... the correct flag for English is of course
>> >> the Cross of St George.
>>
>> >I did actually consider this. But many international users would not make
>> >the connection. As far as that goes, the UK flag is more widely used on
>> >the web to denote the English language. But since my web-site is written
>> >in Quebec English, it makes more sense to use the American flag.
>>
>> You should be able to use both. �But Wales, for which you have a flag,
>> is part of the UK. �England is the only major part of the UK which has
>> no surviving active indigenous language other than English.
>
>I've heard about the Northumbrian (Tyneside region of England) dialect
>called 'Geordie'.
A dialect is not a language. Spoken Geordie is just English peculiarly
pronounced with a few local words. Educated Geordies write in normal
English.