Dynamic refresh Javascript

Well, recently i got a task bout creating a stock system. Well, it will be use when there is a SALE. So the stock need to be real time updated, so i browse around bout how to stay update like that. And i got a hint about it and it is using jquery, here it goes :

*This is what is inside time.php


<script src=”http://code.jquery.com/jquery-latest.js”></script>
<script>
$(document).ready(function() {
var refreshTime = setInterval(function() {
$(“#responsecontainer”).load(‘updatetime.php’);
}, 1000);
$.ajaxSetup({ cache: false });
});
</script>

*This is what is inside updatetime.php


<?php
echo date(‘s’);
?>

As you can see there will be 2 file : time.php and updatetime.php, time.php shows the time and updatetime.php gonna be the one that process time.php. The code inside updatetime.php will shows time’s second, the code inside time.php means every 1 second it gonna refresh “ ” with the new one from updatetime.php.

Simply its like that hopefully this will help you all.

Leave a Reply

Your email address will not be published. Required fields are marked *