Results 1 to 5 of 5

Thread: [RESOLVED] auto refresh

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

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

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    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
  •  



Click Here to Expand Forum to Full Width