-1

I am using display view that uses app.js file.In this I retrieve data from database and display using some api in app.js . I need to reload the display automatically evey say, 5 sec.I don't want page be refreshed but be updated.There is div with 'mydiv' which holds the display contents.How can I accomplish this?

1 Answer 1

0

This can be done using JavaScript. To refresh a div every n minutes, you can use setInterval method to call a function every n miliseconds. This function should make ajax request to get data from server and insert the data in HTML. Below code uses jQuery but you can use any other library to get the result.

$(document).ready(function() {
    // get data every 5 seconds and refresh myDiv
    var pingAfter = 5000;  
    var refreshId = setInterval(function() {
        $("#myDiv").load('/partial/data');
    }, pingAfter);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.