Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
混淆javascript setinterval、循环和jquery ajax加载优先级_Javascript_Arrays_Jquery - Fatal编程技术网

混淆javascript setinterval、循环和jquery ajax加载优先级

混淆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

直截了当 我有以下javascript和jquery代码,它们更新了一些选中的行,并对每个datatables行执行了一些操作。这是我的密码:

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张有用的选票