我试图遍历Sqlite DB中的所有表并将它们发送到服务器DB。一切正常,除了当我到达通过$ .get()发送信息的部分时,tbl_name变量已经设置为最后一个值... IE的所有$ .get()调用都使用相同的值tbl_name,最后一个表名。
var submissionID=10;
var varStr;
DEMODB.transaction(function (transaction) {
transaction.executeSql("SELECT name FROM sqlite_master WHERE type='table';", [], function(transaction, results) {
for (var i = 0; i < results.rows.length; i++) {
var tables = results.rows.item(i);
var tbl_name=tables['name'];
if (tbl_name=="__WebKitDatabaseInfoTable__" || tbl_name=="Submission") { continue; }
transaction.executeSql("SELECT * FROM " + tbl_name + " WHERE submissionID=?;", [ID], function(transaction, results) {
varStr="";
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
for (col in row) {
if (col=="submissionID" || col=="ID") { continue; }
varStr += col + "=" + row[col] + '&';
}
}
varStr += 'submissionID=' + submissionID + "&table=" + tbl_name + "&num=" + i;
$.get("script/to/process.aspx",varStr);
}, errorHandler);
}
}, errorHandler);
});
最佳答案
DEMODB.transaction(function (transaction) {
transaction.executeSql("SELECT name FROM sqlite_master WHERE type='table';", [], function(transaction, results) {
for (var i = 0; i < results.rows.length; i++) {
var tables = results.rows.item(i);
handleTable(tables['name'], transaction);
}
}, errorHandler);
});
function handleTable(tbl_name, transaction) {
if (tbl_name=="__WebKitDatabaseInfoTable__" || tbl_name=="Submission") { return; }
transaction.executeSql("SELECT * FROM " + tbl_name + " WHERE submissionID=?;", [ID], function(transaction, results) {
varStr="";
for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
for (col in row) {
if (col=="submissionID" || col=="ID") { continue; }
varStr += col + "=" + row[col] + '&';
}
}
varStr += 'submissionID=' + submissionID + "&table=" + tbl_name + "&num=" + i;
$.get("script/to/process.aspx",varStr);
}, errorHandler);
}