Monday, 15 February 2010

html5 - Take out sqlresultset from a function using javascript websql -



html5 - Take out sqlresultset from a function using javascript websql -

i have function in project. should homecoming result of select request can not it! jresult come out empty transaction function. in first console.log ok , can check content @ end empty!! can not homecoming result of query.

any 1 know problem? there improve way homecoming sqlresultset function?

thanks

function gethistorylist() { var jresult=[]; db.transaction( function(transaction) { transaction.executesql( 'select * history;',[], function (transaction, result) { console.log("query success"); (var i=0; < result.rows.length; i++) { jresult.push(result.rows.item(i)); } console.log(jresult); }, function (transaction, error) { console.log("query error: " + error.message); } ); }, function (error) { console.log("transaction error: " + error.message); }, function () { console.log("transaction success"); } ); console.log(jresult); homecoming jresult; // -> [] }

functions transaction() , executesql() asynchronous. means code after these functions can executed before sql transactions performed.

that's why these function take in parameter callback functions. these functions executed when asynchronous function finish work.

the reason why first console.log works is executed in callback function : after sql request have been performed.

so, if want exploit result request, must in callback function pass in parameter of asynchronous function.

javascript html5 web-sql

No comments:

Post a Comment