Error net :: ERR_INSUFFICIENT_RESOURCES after 2 minutes running jQuery script to create ajax requests

By executing the code below, the page loads fine with the functions dayofweek and hourofday. But shortly after the browser (Chrome) freezes and throws an error: net :: ERR_INSUFFICIENT_RESOURCES and references the jQuery library and my hourofday.js script.

After a few minutes, he begins to get errors like crazy, and he freezes. I can’t even reload the page.

function dayofweek(){ $.ajax({ url: "dayofweek.php", type: "POST", dataType: "xml", success: function (xml){ var day = $(xml).find('day').first().text(); $("#dayofweek").html(day); }, error: function (xhr, status) { }, complete: function (xhr, status) { } }); } function hourofday(){ $.ajax({ url: "hourofday.php", type: "POST", dataType: "xml", success: function (xml){ var response = $(xml).find('response').first().text(); $("#hourofday").html(response); }, error: function (xhr, status) { }, complete: function (xhr, status) { } }); setInterval(dayofweek, 6000); setInterval(hourofday, 6000); } 
+6
source share
1 answer

You have a call to the setInterval(hourofday, 6000); function setInterval(hourofday, 6000); INSIDE, hourofday () function definition! This means that it will return endlessly, calling itself until your computer runs out of memory.

Just move the setInterval (...) OUTSIDE commands from the function definitions.

+7
source

Source: https://habr.com/ru/post/976926/


All Articles