Topic: Time on the page

Hello!
I want to show the server time on the page. But I do not know how to update the time every minute (or second). Please help.

Re: Time on the page

Look at the Comet plugin. It handles intermittant events for you.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Time on the page

Thank you! Try to use it.

Re: Time on the page

Excellent. All happened.
But there is a slight problem. When a request comes time for the server (and this happens once in a minute), at the moment, changing the cursor. It is not nice looks.
Tell me, please, is there a way to solve this problem?

Re: Time on the page

Glad it works for you.

As for the cursor changing, I'm not sure. I'll see what I can find.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Time on the page

I will try to explain better. Sorry for my bad English smile. The cursor changes to "standby", just for a moment.

Re: Time on the page

Still looking....

Please do not apologize for you English. It's way better than my Russian. smile

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Time on the page

I think, i understand what you mean,

try this after $xajax = new xajax() :

$xajax->configure("waitCursor",false);

this should fix your problem

Adrian

EDIT:
But an other idea is to register a non-comet function
something like

Code: PHP

function getTime()

{

  $objResponse = new xajaxResponse();

  $objResponse->assign("timeDiv","innerHTML",date("d.m.Y - H:m:i"));

  return $objResponse;

}



$xajax->register(XAJAX_FUNCTION, "getTime");

and between the "head"-tags of your page do this JS:

Code: PHP

function callTime()

{

  xajax_getTime();

  window.setTimeout("callTime()",1000); //calls callTime every secount (1000 millisecunds)

}

I didn't tried this but it should work, sow you don't have to hold an persistent connection with comet

Re: Time on the page

Hi,

I'm curious about why you need to use ajax at all for the time? And if you do need to show the server time (as opposed to the client pc's time), then why not just get the initial time and then use js to increment it after that?

The following code shows client-side time, which could be easily modified to pass the initial time from the server and then continue to increment it without any asynchronous interaction:

Code: PHP

<html>

<head>

  <title>Show time</title>

  <script language="javascript">

  <!--

    function getthetime(mydate) {

      var hours=mydate.getHours();

      var minutes=mydate.getMinutes();

      var seconds=mydate.getSeconds();

      (hours>=12)?ampm="PM":ampm="AM";

      if (hours>12) hours=hours-12;

      if (hours==0) hours=12;

      if (minutes<=9) minutes="0"+minutes;

      if (seconds<=9) seconds="0"+seconds;



      var mytime="  "+hours+":"+minutes+":"+seconds+" "+ampm;

      document.bannerform.clock1.value=mytime;

    }



    function load_date() {

      if (document.all||document.getElementById) setInterval("getthetime(new Date())",1000);

    }

  // -->

  </script>

</head>

<body onload="load_date();">

    <br><br><br>

    <center>

    <form name="bannerform">

      Current Time: <input type="text" name="clock1" size="10" onfocus="blur()">

    </form>

    </center>

</body>

</html>