2014-10-19 1071 views
6

運行下面的代碼,頁面可以正常加載dayofweek和hourofday函數。但在瀏覽器(Chrome)凍結並出現錯誤後不久:net :: ERR_INSUFFICIENT_RESOURCES並引用了jQuery庫和我的hourofday.js腳本。錯誤net :: ERR_INSUFFICIENT_RESOURCES在運行jQuery腳本2分鐘後發出ajax請求

幾分鐘後,它開始像瘋了似的錯誤,它凍結。我甚至無法重新加載頁面。

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); 
} 

回答

7

您有setInterval(hourofday, 6000);函數調用INSIL在hourofday()函數定義!這意味着它將無限遞歸,自行調用,直到您的計算機內存不足。

只需在函數定義的外部移動setInterval(...)語句即可。