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

Viewed 351

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...

3 Answers

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);  
        }
    });
}
Related