setInterval in JavaScript not working


Question:

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.


Login to See the Rest of the Answer

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.







For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email Address[email protected]