jquery - issue with get array values outside the function in javascript? -


I have created an array that will store dynamic values ​​coming from DB. When I print the array inside the transaction function it is printing when I tried to print the side and I could not get the price. I have declared the array globally what is the problem, my code is as follows;

  function sendCategoryDetails () {var selected_category = $ ('# select-choice: selected'). Val (); Warning ("control:" + selected_category); Var mycoodinates description; Var myLocation = New Array (); Var db = window sqlite plugin.openDatabase ({name: "MYDB"}); db.transaction (function (tx) {tx.executeSql ("select location of location WHERE category = '" + selected_category + "';", [], function (tx, ridge) {for (var i = 0; i & lt; res.rows.length; i ++) {myLocation [i] = res.rows.item (i) .post;} alert (myLocation + "length:" + myLocation.length); // value print There is no value}}}}; alert (my position + "length:" + myLocation.length); // is not getting value, it is showing the length 0}   

Suggestions?

tx.executeSql is an async function. code> alerts works because Callback and async processing has ended. After the function is triggered, the alert function has ended, thus it is undefined

Solution: Work inside callback or call another function is passed as a parameter with the array and works there.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -