Talha Habib Talha Habib - 1 year ago 183
jQuery Question

refresh container without refreshing page

By using this

<?php echo date('r'); ?>
, is there any way i can refresh simple container (span where my time is echo) without refreshing the page Here this is my page i am displaying date and time here

Answer Source

Send AJAX request periodically to a PHP file which echos date.

(function worker() {
    url: 'backend.php', 
    success: function(data) {
    complete: function() {
      // Schedule the next request when the current one's complete
      setTimeout(worker, 5000);

Call this worker() function on the div of the date.


echo date('Y-m-d H:i:s'); // This is just a sample date format. YOUR DATE FORMAT.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download