Can anyone please tell me how to write a small div container in HTML that refreshes its contents from the data in mysql every 5 min.
T开发者_如何学Gohis is similar to twitter updates in some webpages which show updates as and when tweeted.
Thanks.
You can use the setInterval
function to make AJAX calls:
setInterval(function() {
$('#dynamicDiv').load('DynamicDivData.php');
}, 5 * 60 * 1000); //300,000 milliseconds.
Where DynamicDivData.php
connects to the database and returns the HTML to put in the <div>
.
To avoid caching issues, you can append a random number in the querystring:
$('#dynamicDiv').load('DynamicDivData.php?NoCache=' + Math.random());
With Jquery
$(document).ready(function () { $("#live").load("ajax.php"); var refreshId = setInterval(function () { $("#live").load('ajax.php?randval=' + Math.random()); }, 3000); });
it calls ajax.php in first load and every 3 seconds to #live div.
精彩评论