我有一個網頁,我從服務器獲取一些數據。我用servlet從服務器獲取數據。我需要每隔5秒鐘獲取一次數據inerval.I在我的腳本中使用了ajax調用,但是在幾次調用之後,網頁變得沒有響應。我發現了一件事,我在這裏再次替換了整個html頁面,我怎樣才能從輸出html內容(這裏是page_html)中分離出特定的div。我只想ajax調用後網頁變得沒有響應
setInterval("update_content();", 5000);
function update_content(){
$.ajax({
url: "url", // post it back to itself - use relative path or consistent www. or non-www. to avoid cross domain security issues
type: "POST",
async: true,
cache: false, // be sure not to cache results
})
.done(function(page_html) {
var newDoc = document.open("text/html", "replace");
newDoc.write(page_html);
newDoc.close();
});
}
使用'setInterval(update_content,5000);'而不是'setInterval(「update_content();」,5000);'。 –
在控制檯中是否有任何錯誤? –
這很奇怪。你能在JSFIddle上發佈最小可重現的例子嗎? –