混淆javascript setinterval、循环和jquery ajax加载优先级
直截了当 我有以下javascript和jquery代码,它们更新了一些选中的行,并对每个datatables行执行了一些操作。这是我的密码:混淆javascript setinterval、循环和jquery ajax加载优先级,javascript,arrays,jquery,Javascript,Arrays,Jquery,直截了当 我有以下javascript和jquery代码,它们更新了一些选中的行,并对每个datatables行执行了一些操作。这是我的密码: function checkUpdate(){ setInterval(function(){ var listLength = updateList.length; if(listLength > 0){ for(var r=0; r<listLength; r++){ // console
function checkUpdate(){
setInterval(function(){
var listLength = updateList.length;
if(listLength > 0){
for(var r=0; r<listLength; r++){
// console.log(r)
var clID = updateList[r];
// console.log(clID)
var rRow = $('#dataTable tbody tr').find('td[data-clientid="'+clID+'"]').parent('tr');
// console.log(rRow)
var rRowIndex = rRow.index();
// console.log(rRowIndex)
var rRowDataIndex = oTable.fnGetPosition(rRow[0]);
console.log(rRowDataIndex)
$.ajax({
url: '/cgi-bin/if-Clients-list.jpl',
data: 'session=' + recievedSession + '&clientid=' + clID + '&outputformat=json',
dataType: 'json',
success: function(rowData){
// console.log(rowData)
var newRow = [];
var newOrderedRow = [];
console.log(rRowDataIndex)
newRow.push(rRowDataIndex+1, "");
for (var title in rowData[0]){
newRow.push(rowData[0][title]);
}
console.log(newRow)
},
});
};
}
},2000)
函数checkUpdate(){
setInterval(函数(){
var listLength=updateList.length;
如果(listLength>0){
对于(var r=0;r,您需要将AJAX调用包装在一个闭包中,以便每次通过循环捕获rRowDataIndex
的值
function checkUpdate() {
setInterval(function () {
var listLength = updateList.length;
if (listLength > 0) {
for (var r = 0; r < listLength; r++) {
// console.log(r)
var clID = updateList[r];
// console.log(clID)
var rRow = $('#dataTable tbody tr').find('td[data-clientid="' + clID + '"]').parent('tr');
// console.log(rRow)
var rRowIndex = rRow.index();
// console.log(rRowIndex)
var rRowDataIndex = oTable.fnGetPosition(rRow[0]);
console.log(rRowDataIndex)
(function (rRowDataIndex) {
$.ajax({
url: '/cgi-bin/if-Clients-list.jpl',
data: 'session=' + recievedSession + '&clientid=' + clID + '&outputformat=json',
dataType: 'json',
success: function (rowData) {
// console.log(rowData)
var newRow = [];
var newOrderedRow = [];
console.log(rRowDataIndex)
newRow.push(rRowDataIndex + 1, "");
for (var title in rowData[0]) {
newRow.push(rowData[0][title]);
}
console.log(newRow)
},
});
})(rRowDataIndex);
};
}
}, 2000);
}
函数checkUpdate(){
setInterval(函数(){
var listLength=updateList.length;
如果(listLength>0){
for(var r=0;r
非常感谢,它帮了我很大的忙。希望我能增加10张有用的选票