我希望将一些 JSON 内容从 Drupal 网站存储到 PhoneGap 应用程序中的数据库表中。我正在使用 ajax 来执行此操作。当我运行以下代码并检查表时,我被告知它是空的。有人知道我如何填充这张表吗?
$('#newDiv').live('pageshow',function(){
function queryDB(tx) {
tx.executeSql("SELECT * FROM 'tableA'", [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
alert("Table: " + len + " rows were found.");
}
}
function createTable(tx) {
tx.executeSql('DROP TABLE IF EXISTS "tableA"');
var sql = "CREATE TABLE IF NOT EXISTS 'tableA' (id INTEGER PRIMARY KEY AUTOINCREMENT, step VARCHAR(50), text VARCHAR(50))";
tx.executeSql(sql, [], successCB, errorCB);
}
db.transaction(createTable, errorCB, successCB);
$.ajax({
url: myURL,
type: 'post',
data: 'tid=4',
dataType: 'json',
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('new_page_node_view - failed to retrieve page node');
console.log(JSON.stringify(XMLHttpRequest));
console.log(JSON.stringify(textStatus));
console.log(JSON.stringify(errorThrown));
},
success: function (data) {
$.each(data, function (node_index,node_value) {
db.transaction(function(tx){
tx.executeSql("INSERT INTO 'tableA' (step, text) VALUES (?, ?)",[node_value.title, node_value.body]);
});
});
}
});
db.transaction(queryDB, errorCB, successCB);
});