Json Data Insert Sqlit Database Not Working
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_DA
Solution 1:
Old question but this might help others.
That error is usually caused by the transaction tx
being stale.
This is because of the ajax call and by the time your ajax callback gets hit that tx
object is no longer valid. The same happens if you use setTimeout
or any time consuming non-Websql operation aswell.
To avoid that simply, create the transaction inside in the callback.
E.g
functiondbReady() {
$.getJSON('http://echo.jsontest.com/key/value/one/two',function(data) {
db.transaction(function(tx) {
alert("5");
$.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'); });
});
}
Post a Comment for "Json Data Insert Sqlit Database Not Working"