0
我正在編寫一個移動應用程序,用於在本地使用Sqlite存儲數據。在過去的4天裏,我一直在試圖弄清楚爲什麼當Jquery和phonegap完全加載時數據庫沒有創建。在sqlite中創建語句不起作用,回調函數不起作用。 deviceready不起作用,但如果檢查sqlite支持它會觸發。示例代碼是別人的代碼,但發生了同樣的事情。有人可以幫幫我嗎?Phonegap deviceready not responding/firing
var jqmReady = $.Deferred(),
pgReady = $.Deferred();
// jqm page is ready
$(document).bind("pageinit", jqmReady.resolve);
// phonegap ready
document.addEventListener("deviceready", pgReady.resolve, false);
// all ready, throw a custom 'onDeviceready' event
$.when(jqmReady, pgReady).then(function(){
$(document).trigger("onDeviceready");
});
function onDeviceReady(){
db.transaction(populateDB, errorCB, successCB);
}
//create table and insert some record
function populateDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS SoccerPlayer (id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL, Club TEXT NOT NULL)');
tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Alexandre Pato", "AC Milan")');
tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Van Persie", "Arsenal")');
}
//function will be called when an error occurred
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
//function will be called when process succeed
function successCB() {
alert("success!");
db.transaction(queryDB,errorCB);
}
謝謝傑弗瑞,我按照你的指示,它的工作。 – 2013-02-24 00:18:36