【发布时间】:2016-01-18 19:11:33
【问题描述】:
我有一个网页,我在其中从服务器获取一些数据。我使用 servlet 从服务器获取数据。我需要每 5 秒 inerval 获取数据。我在脚本中使用了 ajax 调用,但是在几次调用之后,网页变得没有响应。我发现一件事在这里我已经再次替换了整个 html 页面,我怎样才能将特定的 div 与输出的 html 内容(这里 page_html)分开。我只想替换 div
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 上发布最小的可重现示例吗?
-
异步调用有什么问题吗?
-
@YeldarKurmangaliyev:嘿,我找到了问题,你能帮我多一点吗,请查看编辑...
标签: javascript jquery html ajax web-applications