【发布时间】:2014-10-16 06:50:11
【问题描述】:
我从一个网站上获得了这段代码,并根据我的需要进行了修改:
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
</head>
<div id="links">
</div>
<script language="javascript" type="text/javascript">
var timeout = setTimeout(reloadChat, 5000);
function reloadChat () {
$('#links').load('test.php #links',function () {
$(this).unwrap();
timeout = setTimeout(reloadChat, 5000);
});
}
</script>
在test.php中:
<?php echo 'test'; ?>
所以我希望在链接 div 中每 5 秒调用一次 test.php。我怎样才能做到这一点?
【问题讨论】:
-
你包含jquery库吗
-
是的,我在头顶得到了
-
您使用的是旧版本的 ogf jquery ,请尝试最新版本
-
AJAX 轮询是一种反模式,应该不惜一切代价避免。它不是一个可扩展的解决方案,并且会以最小的并发负载导致服务器端性能问题。当您需要保持客户端/服务器端数据紧密同步时,一个更好的解决方案是使用观察者模式。在这种情况下,websockets。
标签: javascript php jquery ajax