javascript - transaction.executeSql Success function error -
i did function select data db , show alert, i'm getting following error in success function:
cannot read property 'rows' of undefined retrievedata
here functions
function selectall(){ db.transaction( function(transaction) { transaction.executesql("select * cdprodutos", [], retrievedata()); //the retrievedata function data sent/returned in parameters (transation, results) }); } function retrievedata(transaction, results) { for(var = 0; < results.rows.length; i++) { var data = results.rows.item(i)['id'] alert(data.value); } }
it looks function being executed , there no data being passed it, rows
property coming undefined.
writing ()
after retrievedata
, invoking function immediately. remove ()
use callback.
it appears need pass data along it, anonymous function trick here:
function selectall(){ db.transaction( function(transaction) { transaction.executesql("select * cdprodutos", [], function() { retrievedata(transation, results); //not sure results comes from? parameter of function?? }); }); } function retrievedata(transaction, results) { for(var = 0; < results.rows.length; i++) { var data = results.rows.item(i)['id'] alert(data.value); } }
Comments
Post a Comment