|
-
Feb 13th, 2010, 11:26 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] auto refresh
i need to refresh the clock using javascript, now what i'm trying is open a file containing the php code for getting the time, and i use php since i want the server time, not the clients time, and last time i tried a clock with javascript it was a bit bugged...
the code of time.php:
Code:
<?php
echo date("H:i:s", time());
?>
and the code of javascript or ajax, whatever... it seems to work in firefox, chrome and safari, but not IE.
Code:
function getTime(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('time').innerHTML=xmlHttp.responseText;
setTimeout('getTime()',1000);
}
}
xmlHttp.open("GET","time.php",true);
xmlHttp.send(null);
}
window.onload=function(){
setTimeout('getTime()',1000);
}
Last edited by Justa Lol; Feb 13th, 2010 at 11:26 AM.
Reason: spelling corrections
-
Feb 13th, 2010, 12:28 PM
#2
Re: auto refresh
.. is the only point of this to make a clock? you would be better off doing it with pure JavaScript rather than making a request every second just to update the time. this clock uses pure javascript and cookies. this example lets you specify the start time (using ASP, though it could be easily changed to PHP) and then just uses JavaScript to maintain it.
-
Feb 13th, 2010, 12:45 PM
#3
Thread Starter
Fanatic Member
Re: auto refresh
well as i said i used php because last time i used a js clock it was kinda bugged, but well, i'll give it a try...
-
Feb 13th, 2010, 01:50 PM
#4
Re: auto refresh
just because you found some script on the internet (and possibly tried to modify it) that didn't work doesn't mean something is impossible. what you're doing now is probably the absolute worst, most inefficient way of solving your problem -- even if you could get it to work.
-
Feb 13th, 2010, 02:24 PM
#5
Thread Starter
Fanatic Member
Re: auto refresh
ok well, i take your word for it..
Lazy people like to find a shortcut around everything
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|