开发者

jquery div container that updates from mysql every 5 min

开发者 https://www.devze.com 2022-12-26 15:50 出处:网络
Can anyone please tell me how to write a small div container in HTML that refreshes itscontents from the data in mysql every 5 min.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消