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.
xajax PHP Class Library - The easiest way to develop asynchronous Ajax applications with PHP
You are not logged in. Please login or register.
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.
Look at the Comet plugin. It handles intermittant events for you.
Ed
Thank you! Try to use it.
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?
Glad it works for you.
As for the cursor changing, I'm not sure. I'll see what I can find.
Ed
I will try to explain better. Sorry for my bad English
. The cursor changes to "standby", just for a moment.
Still looking....
Please do not apologize for you English. It's way better than my Russian. ![]()
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
{
$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:
{
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
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:
<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>
Posts [ 9 ]
Currently used extensions: pun_repository. Copyright © 2008 PunBB
[ Generated in 0.836 seconds, 9 queries executed ]