i have this code:
function getData(){
db.transaction(function(tx){
tx.executeSql('SELECT * from q', [], function(tx, result){
var q = [];
for (var i=0; i < result.rows.length; i++) {
q.push(result.rows.item(i));
};
console.log(q.length); // 3
returnData(q);
});
});
}
function returnData(data){
console.log(data.length); // 3
return data;
}
var q = getData(); // undefined
and it don't work as expected (it don't return anything). A assume that happened, because db.transaction
work asynchronous, but i'm using callback to return data. Can somebody explain why it doesn't work and how to fix that?