Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
28
rated 0 times [  30] [ 2]  / answers: 1 / hits: 17496  / 13 Years ago, sun, january 8, 2012, 12:00:00

From a tutorial code like this



function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}

function querySuccess(tx, results) {

}

function errorCB(err) {
alert(Error processing SQL: +err.code);
}

var db = window.openDatabase(Database, 1.0, PhoneGap Demo, 200000);
db.transaction(queryDB, errorCB);


in db.transaction i want to pass a variable as argument to queryDB function, so the code which i think of should looks like



db.transaction(queryDB(id), errorCB);


How I can actually implement this ? Or its simply gonna work like this and my id will be passed and get in tx ?


More From » javascript

 Answers
14

Wrap it in a function again



var id = 'THEID';
db.transaction(function(){
queryDB(id)
}, errorCB);


Note - This is assuming that you're making the API. Some APIs / frameworks insert the required information automatically. For example



//the db.transaction method
function transaction(param, callback) {
//do code stuff
callback(someInternalId); //callback is the function you pass as the first parameter
}


So, if you want to pass your own data in the callback, wrap it in a function. Otherwise, the code you are using may be doing this for you automatically.


[#88165] Friday, January 6, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
danyelletyanah

Total Points: 204
Total Questions: 109
Total Answers: 108

Location: Vanuatu
Member since Fri, Oct 22, 2021
3 Years ago
;