2012-09-22 25 views
-1

我有一個自定義控件保存在div中,只在刷新時更改其內容,所以我想用一些只能刷新div的東西。書的牆壁像概念。通過jquery連續刷新頁面一定的時間差距

+0

這可能會幫助你http://stackoverflow.com/questions/5296815/ajax-browser-refresh-in-background –

回答

1

嘗試這樣

<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> 
1

您可以用setInterval來時間可持續執行的操作。用clearInterval(intv)清除它;

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

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

上面會做5秒鐘的事,然後取消30秒後的輪詢。

+0

感謝您的回覆@chovy,但我的網頁我死了。 – Manoj

+0

你得到的錯誤是什麼?你可以粘貼一個jsfiddle嗎? – chovy

+0

知道了chovy!解決方案就是使用數據庫連接進行數據庫連接,這就是如何使用面書圖表。想請教一下...你知道任何類似的遊戲腳本嗎? – Manoj