In this fallowing Example, we are going to update our page content using AJAX and of course we
love AJAX in jQuery flavor. So key to this functionality is JavaScript's
built-in setInterval() function. It lets you to run some javascript
function every X seconds. For example, the following code would pop
alert box every five seconds:
setInterval( "alert('Hello')", 5000 );
Now consider we want to update shouts in our shoutbox every 10 seconds.
function updateShouts(){ // Assuming we have #shoutbox $('#shoutbox').load('latestShouts.php'); } setInterval( "updateShouts()", 10000 );
The code above will run every 10 seconds (10,000 ms) and update the contents of #shotbox with new shouts.
No comments:
Post a Comment