Php 在一定的时间间隔内,通过jquery连续刷新页面

Php 在一定的时间间隔内,通过jquery连续刷新页面,php,Php,我在一个div中保存了一个自定义控件,该控件只在刷新时更改其内容,因此我正在考虑使用一些只能刷新该div的控件。我正在尝试使用类似于facebook墙的概念。像这样尝试 <html> <head> <!-- For ease i'm just using a JQuery version hosted by JQuery- you can download any version and link to it locally --> <script sr

我在一个div中保存了一个自定义控件,该控件只在刷新时更改其内容,因此我正在考虑使用一些只能刷新该div的控件。我正在尝试使用类似于facebook墙的概念。

像这样尝试

<html>
<head>
<!-- For ease i'm just using a JQuery version hosted by JQuery- you can download any version and link to it locally -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
 $("#responsecontainer").load("response.php");
  var refreshId = setInterval(function() {
  $("#responsecontainer").load('response.php?randval='+ Math.random());
 }, 9000);
 $.ajaxSetup({ cache: false });
});
</script>
</head>
<body>

<div id="responsecontainer">
</div>
</body>
</html>

您可以使用setInterval继续执行操作。用clearIntervalintv清除它

var intv = setInterval(function(){
 //do stuff here every 5 seconds
}, 5000);

setTimeout(function(){
  clearInterval(intv);
}, 30000);

上面的操作将在5秒后执行,然后在30秒后取消轮询。

这可能会帮助您感谢您的回复@chovy,但我的页面已关闭。您收到的错误是什么?你能粘贴一个JSFIDLE吗?找到了!解决方案是通过池进行数据库连接,这就是face book ticker的工作原理。请对此提出建议……你们知道有类似的脚本吗。