I tried to JSON
data insert into SqLit
database in PhoneGap. I created a table with two columns, like this:
function setup(tx) {
tx.executeSql('DROP TABLE IF EXISTS HEADER_DATA');
tx.executeSql("create table if not exists bookinformation(inserkey TEXT, key TEXT)");
}
This code runs successfully and the table is created. Then, I insert JSON data into the bookinformation
table, like this:
function dbReady() {
db.transaction(function(tx) {
alert("5");
$.getJSON('http://echo.jsontest.com/key/value/one/two',function(data){
$.each(data, function(i, dat){
tx.executeSql('INSERT OR REPLACE INTO bookinformation (inserkey, key) VALUES("'+data.one+'", "'+data.key+'")');
alert("completed");
});
});
}, errorHandler, function() { alert('added row'); });
}
However, the insert statement fails. I get this error:
Uncaught InvalidStateError:Failed to execute 'executeSql' on 'SQLTransaction':SQL execution is disallowed
What is causing this error?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…