0
我試圖通過訪問一個Web服務更新我的DataTable
中的單元格的值從脫機到聯機(反之亦然)。遍歷錶行並執行每行setInterval似乎並不工作
var $myTable = $("#my-table").dataTable();
var $myTableRows = $myTable.fnGetNodes();
for(var i=0; i<$myTableRows.length; i++) {
var $currentRowCount = i;
var $interval = $($myTableRows[i]).find("td:eq(9)").html();
var $timeout = $($myTableRows[i]).find("td:eq(10)").html();
var $dataINeedToPass = $($myTableRows[i]).find("td span:eq(4)").html();
setInterval(function() { updateStuffOnTheTable($interval, $timeout, $dataINeedToPass, i); }, 4000);
}
function updateStuffOnTheTable(interval, timeout, dataINeedToPass, row) {
var $stuff = "Offline";
var ajaxCall = $.ajax({
url : "https://localhost:8443/cxf/mywebservice/" + dataINeedToPass,
type : "GET",
dataType : 'text',
timeout: 2000
}).done(function(data) {
$stuff = "Online";
})
.fail(function(data) {
$stuff = "Offline";
})
.always(function(data) {
$myTable.fnUpdate($stuff, row, 2);
})
}
問題是,AJAX請求只執行一次而不是每4000ms。我在這裏錯過了什麼?