当我尝试处理一个时,它失败了:
未捕获的错误:INVALID_STATE_ERR:文件中的 DOM 异常 11:///android_asset/www/library/custom.js:39
但是当我尝试第二个过程时,它就好了。
var db = window.openDatabase("Pemberton", "1.0", "Pemberton Stay App", 200000);
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
db.transaction(populateDB, errorCB, successCB);
}
过程1:
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS eat');
tx.executeSql('CREATE TABLE IF NOT EXISTS eat (id, image, title)');
var queries = new Array();
$.getJSON( serviceURL + 'category-list.php?cid=1&p=?', function(data) {
var results = data.items;
$.each(results,function(index,record){
if( record.id != undefined )
tx.executeSql('INSERT INTO eat (id, image, title) VALUES ("'+record.id+'","'+record.image+'","'+record.title+'")');
});
});
}
过程2:
function populateDB(tx)
{
tx.executeSql('INSERT INTO eat (id, image, title) VALUES (2,"one.jkd","OneFirst")');
tx.executeSql('INSERT INTO eat (id, image, title) VALUES (2, "two.png","Second")');
tx.executeSql('INSERT INTO eat (id, image, title) VALUES (3, "thr.png","Third")');
tx.executeSql('INSERT INTO eat (id, image, title) VALUES (4, "fou.png","Fourth")');
tx.executeSql('INSERT INTO eat (id, image, title) VALUES (5, "fiv.png","Fifth")');
}