Page 1 of 1

Clock update <?php echo microtime();?> Put into eho/msec.php

Posted: Fri Apr 11, 2014 9:01 am
by xcislav
Now I need every time to press F5 <?php echo microtime(); ?>
But if I want to update the server clock every second what [setInterval] should i write?

Code: Select all

<script>
function update(){
    $('body').load('/eho.php');
}
update();
setInterval(function(){ update() }, 1000); 
</script>
I added to that code:
<?php echo microtime(); ?>
Changed places, files. I see no way how to make it work.

Re: Clock update <?php echo microtime();?> Put into eho/msec

Posted: Fri Apr 11, 2014 9:33 am
by Christopher
If you want to make calls to the server every second (which sounds crazy) the use the jQuery ajax() function to make the calls.

Re: Clock update <?php echo microtime();?> Put into eho/msec

Posted: Fri Apr 11, 2014 10:16 am
by xcislav
5+ seconds, not so crazy.

After apache+php+pdo setup there was a lot of not working things (themselves). And it works at last. I know jQuery is like something even more additional. And I read Ajax is for advanced javascript professionals.

So, it's a pity that it's completely out of the question to put into reality my try :(

Re: Clock update <?php echo microtime();?> Put into eho/msec

Posted: Fri Apr 11, 2014 2:10 pm
by Christopher
It doesn't matter whether it is 1 second or 5 seconds. When I hear "update the server clock" it sounds like there is probably a better way to achieve your goal. Ajax is really not that difficult. jQuery makes it very easy. Ajax would be the preferred way to make calls to the server that are not initiated by a user action.

What is your goal when say "update the server clock" ?

Re: Clock update <?php echo microtime();?> Put into eho/msec

Posted: Mon Apr 14, 2014 1:06 pm
by xcislav
Ajax (pure JS no JQ).
Of three scripts that were given to me only one was working.
From it i took the unknown elements to internet search. But lots of water and queries (that take away).

Code: Select all

window.XMLHttpRequest
new XMLHttpRequest()(
"
Microsoft.XMLHTTP
")
if !== null && undefined
onreadystatechange = function() { if(
readyState == 4
document.body.innerHTML
.respondeText
.open("GET", "/eho.php", true)
;
.send(null);
window.onload
setInterval