javascript - Why am I unable to access this global variable? -
i have variable inside of loop can't accessed outside though i've made global. why unable access it? variable "finalvar" here's code:
$(function(){ var successfullstatements = $("#successfullstatements"), errors = $("#errors") html5sql.process( [{ sql:"select * starwarscharacters name=?;", data:[jsonvar] }], function(transaction, results, rowsarray){ for(var = 0; < rowsarray.length; i++){ //the variable tried make global window.finalvar = rowsarray[i].name; } }, function(error, statement){ } ); }); }); alert(finalvar); //tried checking see if variable accessed
html5sql.process asynchronous function. so, finalvar not populated unless function pass html5sql.process executed. executed when results fetched. so, may have move alert place result getting populated.
$(function() { var successfullstatements = $("#successfullstatements"), errors = $("#errors") html5sql.process( [{ sql: "select * starwarscharacters name=?;", data: [jsonvar] }], function(transaction, results, rowsarray) { (var = 0; < rowsarray.length; i++) { //the variable tried make global alert(rowsarray[i].name); } }, function(error, statement) {} ); });
Comments
Post a Comment