I have a function and i want to call it in a other function to get the API key. If i do this i the return value is undefined.
How can i solve this?
function getApiKey(callback) {
var db = app.db;
db.transaction(
function (tx) {
tx.executeSql("SELECT api_key FROM settings WHERE id='1'", [], function (tx, result) {
var apiKey = result.rows.item(0).api_key;
alert(apiKey); // here it works
return apiKey;
});
}
);
}
function getData() {
var myKey = getApiKey();
alert(myKey); // undefined
}