DataTable
我正在尝试通过访问 Web 服务将单元格的值从离线更新为在线(反之亦然) 。
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 请求只执行一次,而不是每 4000 毫秒。我在这里想念什么?