我有以下测试代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ajax - one variable test</title>
<style>
body{ font-size: 12px; font-family: Arial;}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<ol id="variable1"><var1></ol>
<script>
setInterval(function()
{
$("#variable1").load("ajax_v00.html")
},3000);
</script>
</body>
</html>我使用的是一个嵌入式web服务器,它向var1报告状态。
例子:好的,或者抬头
上面的内容破坏了我测试过的任何浏览器。有人能看到我是不是做错了什么吗?
谢谢。
发布于 2013-08-30 15:51:58
请求可能需要超过3秒来执行,从而堆叠请求,直到浏览器无法处理所有请求并崩溃.不要使用间隔,您应该使用一个超时,该超时将在最后一个请求完成后3秒执行请求。在此:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ajax - one variable test</title>
<style>
body{ font-size: 12px; font-family: Arial;}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<ol id="variable1"><var1></ol>
<script>
function doRefresh()
{
$.ajax({
url:"ajax_v00.html",
success:function(data){
$("#variable1").html(data);
setTimeout(doRefresh,3000);
}
});
}
setTimeout(doRefresh,3000);
</script>
</body>
</html>https://stackoverflow.com/questions/18536274
复制相似问题