简体   繁体   中英

how to page without refresh show data in javascript to run every 2-5 minute

Can you help me, I will try to crud application in this one loaddata(); it's my function. any other user adds data then without refresh show in my table how to this possible.

function loaddata() {
    $.ajax({
        url : 'load.php',
        type : 'POST',
        success : function (data) {
            $("#table-data").html(data);  
        }
    });
}

This is my function any user adds data than this function automatically calls how to possible.

Currently after the refresh page show all data but I will try automatically showplace help me...

Window setInterval() Method

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).

The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.

The ID value returned by setInterval() is used as the parameter for the clearInterval() method.

In your case you try it.

setInterval(loaddata, 5000);

Tip : 1000 ms = 1 second.

You can use the setInterval function to set limit howmany time to see it.

setInterval(loaddata, 5000); inside argument first_name is your function name and secound is time(milisecound) to useit.

Just create an interval before your function:

setInterval(loaddata, 300000); //300000 MS == 5 minutes

function loaddata() {
    $.ajax({
        url : 'load.php',
        type : 'POST',
        success : function (data) {
            $("#table-data").html(data);  
        }
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM