Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error net::ERR_INSUFFICIENT_RESOURCES after 2 minutes of running jQuery script making ajax requests

Running the code below, the page loads fine with the dayofweek and hourofday functions. But shortly after the browser (Chrome) freezes up and gives the error : net::ERR_INSUFFICIENT_RESOURCES and refers to the jQuery library and my hourofday.js script.

After a few mins it starts getting errors like crazy and it 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);
}
like image 794
Daniel Avatar asked Oct 19 '14 05:10

Daniel


1 Answers

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

Just move the setInterval(...) statements OUTSIDE of the function definitions.

like image 152
Leonardo Gonzalez Avatar answered Nov 10 '22 02:11

Leonardo Gonzalez