Automatically update time in PHP using Ajax -
how automatically update time in php using ajax..the below command work refreshing page hit f5 or reload button..
echo date('s');
or if necessary update time using ajax in php..
so can done using php , ajax. lets have 2 files index.php , timer.php. can achieve desired results doing following.
in index.php
<?php echo "<html> <head> <title>todo supply title</title> <meta charset='utf-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <script src='http://code.jquery.com/jquery.js'></script> <script> $(document).ready(function(){ setinterval(_inittimer, 1000); }); function _inittimer(){ $.ajax({ url: 'timer.php', success: function(data) { console.log(data); data = data.split(':'); $('#hrs').html(data[0]); $('#mins').html(data[1]); $('#secs').html(data[2]); } }); } </script> </head> <body> <span id='hrs'>0</span>:<span id='mins'>0</span>:<span id='secs'>0</span> </body> </html>";
in timer.php
<?php echo date('h:i:s a');
Comments
Post a Comment