Cordova – How to wait until the callback function returns?

I am using phonegap to make an Android application. I am using phonegap’s Storage api to query the database. This is my code:

function directPath(src, dest)
{
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db. transaction(queryDB, errorCB);
return arrayroute;
}

function queryDB(tx)
{
tx.executeSql(query, [], querySuccess, errorCB);
}

function querySuccess(tx,results) {
//Write some code here.
}

function errorCB(err) {
alert("Error in SQL: "+ err);
}

The problem is that I want to wait until the callback method querySuccess finishes execution before returning from the directPath method .

Don’t try to fight against asynchrony: your app may eventually seem unresponsive to users. For later For any code executed, please use the querySuccess callback.

I am using phonegap to make an Android application. I am using phonegap’s Storage api to query the database. This is my code:

function directPath(src, dest)
{
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo" , 200000 );
db.transaction(queryDB, errorCB);
return arrayroute;
}

function queryDB(tx)
{
tx .executeSql(query, [], querySuccess, errorCB);
}

function querySuccess(tx,results) {
//Write some code here.
}

function errorCB(err) {
alert("Error in SQL: "+ err);
}

The problem is that I want to wait until the callback method querySuccess Finish execution before returning from the directPath method.

Don’t try to fight against asynchrony: your application may eventually appear to be unresponsive to the user. For any code that must be executed later , Please use querySuccess callback.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3752 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.