i am trying to store the json data into SQLite using Ajax. Here's my code :
var db = window.openDatabase("Pemda", "1.0", "Database Pemda", 200000);
db.transaction(populateDB, errorCB, successCB);
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS PEMDA2');
tx.executeSql('CREATE TABLE IF NOT EXISTS PEMDA2 (id unique, name)');
$.ajax({
url: "http://ift.tt/1ypHmim",
dataType: "json",
success: function(parsed_json898) {
$.each(parsed_json898, function(x,item){
myname = item.name;
myid = item.id;
tx.executeSql('INSERT INTO PEMDA2 (id, name) VALUES ('+myid+', "'+myname+'")');
});
},
timeout: 30000,
error:function(){
alert("Error");
}
});
}
But, the code gives the error : Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
How to fix this ? Thanks for your help.
Aucun commentaire:
Enregistrer un commentaire