Auto refresh function in every 30 seconds without reload the page in javascript
Auto refresh function in every 30 seconds
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Auto refresh function in every 30 seconds without reload the page in javascript
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Chris LoveRank #332 · 7.5K reputationPosted Oct 13, 2023, 6:17 AM EDT
Great question
Now to answer your question you can use a setInterval like this:
setInterval(() => {
muFunction();
}, 30000);
Raj BhattRank #513 · 4.8K reputationPosted Oct 13, 2023, 10:34 PM EDT
you can use the
setIntervalfunction to implement an auto-refresh function that executes a specified function at regular intervalsvar refreshInterval = setInterval(function() { refreshContent(); }, 30000);Auto Refresh Example This content will be refreshed every 30 seconds. $(document).ready(function() { // Function to load and refresh content function refreshContent() { // Replace this with your actual content loading logic // For example, load content from an API var newData = "New content loaded at: " + new Date(); // Update the content in your HTML $("#refreshed-content").text(newData); } // Initial content load refreshContent(); // Set up auto-refresh every 30 seconds var refreshInterval = setInterval(function() { refreshContent(); }, 30000); });