|
-
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
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
|