Populating Cordova SQLite storage with the JQuery API

For review, you should have the following code in the the onDeviceReady function in www/js/index.js:

var db = window.sqlitePlugin.openDatabase({name: «test.db»});
db.executeSql(«DROP TABLE IF EXISTS tt»);
db.executeSql(«CREATE TABLE tt (data)»);

$.ajax({
url: ‘https://api.github.com/users/litehelpers/repos’,
dataType: ‘json’,
success: function(res) {
console.log(‘Got AJAX response: ‘ + JSON.stringify(res));
$.each(res, function(i, item) {
$.each(data, function(i, item) {
console.log(‘item: ‘ + JSON.stringify(item));
tx.executeSql(«INSERT INTO tt values (?)», JSON.stringify(item));
});
}, function(e) {
console.log(‘Transaction error: ‘ + e.message);
alert(‘Transaction error: ‘ + e.message);
}, function() {
db.executeSql(‘SELECT COUNT(*) FROM tt’, [], function(res) {
console.log(‘Check SELECT result: ‘ + JSON.stringify(res.rows.item(0)));
alert(‘Transaction finished, check record count: ‘ + JSON.stringify(res.rows.item(0)));
});
});
},
error: function(e) {
console.log(‘Got ERROR: ‘ + JSON.stringify(e));
alert(‘Got ERROR: ‘ + JSON.stringify(e));
}
});
Continua leyendo «Populating Cordova SQLite storage with the JQuery API»

Entradas relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *