Live timer using jquery ajax and php

This simple script allows you to display the live timer. It’s easy to modify the design of the timer using html elements and CSS.

index.php

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
 $(document).ready(function(){
     setInterval(ajaxcall, 1000);
 });
 function ajaxcall(){
     $.ajax({
         url: 'gettime.php',
         success: function(data) {
             data = data.split(':');
             $('#hours').html(data[0]);
             $('#minutes').html(data[1]);
             $('#seconds').html(data[2]);
         }
     });
 }
</script>
<span id="hours">0</span>:<span id="minutes">0</span>:<span id="seconds">0</span>

gettime.php

<?php    echo $date = date('h:i:s A'); ?>
Advertisements

4 thoughts on “Live timer using jquery ajax and php

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s