![](/img/trans.png)
[英]setInterval callback that calls another callback function is not working
[英]setInterval not working with callback function
我正在嘗試使用setInterval調用將使用ajax加載訂單的函數。 但是,當我將參數傳遞給回調時,setInterval函數將停止工作。 w ^
如果我不傳遞任何論點,它就會開始工作。
關於如何使它與參數一起使用的任何想法? 下面是我的代碼
先感謝您!
function httpGetRequest(page){
$.get(page)
.done(function(data){
$(".display_orders").html(data);
});
}
setInterval(httpGetRequest('load_orders.php'), 30000);
在這種情況下
setInterval (httpGetRequest('load_orders.php'), 30000);
該函數立即執行
這樣使用
setInterval ( function() {
httpGetRequest('load_orders.php')
}, 30000);
每當使用setInterval
或setTimeout
確保為其提供一個變量名,以便在需要時可以將其取消。
var orderInterval = setInterval(function(){httpGetRequest('load_orders.php');}, 30000);
如果您想停止它,現在可以調用:
clearInterval(orderInterval);
另一種方法是使用以下語法:
setInterval(httpGetRequest, 30000, 'load_orders.php');
您也可以這樣打電話。
function myFunction()
{
httpGetRequest('load_orders.php');
}
function httpGetRequest(page){
$.get(page)
.done(function(data){
$(".display_orders").html(data);
});
}
setInterval (myFunction, 30000);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.