Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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 避免iPhone超时_Javascript_Iphone_Timeout - Fatal编程技术网

Javascript 避免iPhone超时

Javascript 避免iPhone超时,javascript,iphone,timeout,Javascript,Iphone,Timeout,我正在寻找一个好的策略,从AJAX调用中插入大约2500个id firstName-lastName元组(600KB)。超时发生在AJAX调用完成后,并且我正在本地存储数据库中存储数据时。数据是XML格式的。我现在要做的是通过对数据执行jQuery.each()来将XML数据转换为对象 associateNames[index] = { firstName:jQuery(value).find("First").text(), lastName:jQuery(value).find(

我正在寻找一个好的策略,从AJAX调用中插入大约2500个id firstName-lastName元组(600KB)。超时发生在AJAX调用完成后,并且我正在本地存储数据库中存储数据时。数据是XML格式的。我现在要做的是通过对数据执行jQuery.each()来将XML数据转换为对象

associateNames[index] = {
   firstName:jQuery(value).find("First").text(),
   lastName:jQuery(value).find("Last").text(),
   id:jQuery(value).find("ID").text()
};
然后我将这个对象传递给一个函数,该函数创建一个表并插入这个数据。该功能的主要部分是

    query2.executeSql('CREATE TABLE directory (id unique, fullName)', [],

        // On Success
            function(query, result) {
                jQuery.each(data, function(index, value) {
                    var querySQL = 'INSERT INTO directory (id, fullName) VALUES (' + value.id +
                            ', "'+ encodeURI(value.firstName) + encodeURI(value.lastName) + '")';
                    query.executeSql(querySQL);
                });
            },
iPhone不支持网络工作者。应该有一种方法可以使用setInterval()一次处理一段数据,但是我被卡住了。如果你有什么想法,请告诉我


谢谢

我认为“数据”是数组,对吗?如果是这样的话,你可以这样做:

  ...
  //on Success
  function(query, result){
    setTimeout(function(){  //just in case Ajax took a while too..
        var executeBatch = function(startIndex){
            for(var i = startIndex; i < startIndex+50; i++){
                if(i >= data.length) return;
                //do your execute query on data[i]..
            }
            //after short while do the next batch..
            setTimeout(function(){ executeBatch(startIndex+50) }, 50);
        };
        executeBatch(0);
    }, 100);
  }
);
。。。
//论成功
函数(查询、结果){
setTimeout(function(){//以防万一Ajax也花了一段时间。。
var executeBatch=函数(startIndex){
对于(变量i=startIndex;i=data.length)返回;
//是否对数据[i]执行查询。。
}
//过一会儿再做下一批。。
setTimeout(function(){executeBatch(startIndex+50)},50);
};
ExecuteBack(0);
}, 100);
}
);

我认为“数据”是数组,对吗?如果是这样的话,你可以这样做:

  ...
  //on Success
  function(query, result){
    setTimeout(function(){  //just in case Ajax took a while too..
        var executeBatch = function(startIndex){
            for(var i = startIndex; i < startIndex+50; i++){
                if(i >= data.length) return;
                //do your execute query on data[i]..
            }
            //after short while do the next batch..
            setTimeout(function(){ executeBatch(startIndex+50) }, 50);
        };
        executeBatch(0);
    }, 100);
  }
);
。。。
//论成功
函数(查询、结果){
setTimeout(function(){//以防万一Ajax也花了一段时间。。
var executeBatch=函数(startIndex){
对于(变量i=startIndex;i=data.length)返回;
//是否对数据[i]执行查询。。
}
//过一会儿再做下一批。。
setTimeout(function(){executeBatch(startIndex+50)},50);
};
ExecuteBack(0);
}, 100);
}
);

这正是我需要的。谢谢。这正是我需要的。谢谢