setInterval in JavaScript not working


I have a script that I would like to refresh every certain time, I am using "setInterval"; the data is shown the first time but then it no longer refreshes and I get the following error . Could someone guide me or tell me what recirculate to read to be able to refresh my script, please?
Thank you.

Answer: It looks like at the second iteration the totalCasesChart variable is already disposed from the DOM context. That is why you are having that error because there is no document.ready function. Pretty much, when the page refreshes, the browser has to parse the javascript again or worse even repaint the whole DOM Elements.

I suggest you use jQuery with a delay see the code below.

$(document).ready(function () {
var delay = 5000;
setTimeout(function () { window.location = '/YourPageHere'; }, delay);

The code above still executes even when the page reloads. Overall, this is a bad practice and would consume a lot of resources.

Best case, you should look into pushing the content to the UI whenever it is available at the Server side, this way you don't put much stress on the Browser asking for data every after an interval elapses. Don't use JavaScript, it is pain.

Edit this Article
setInterval in JavaScript not working JavaScript Technology published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy