I am trying to populate a javascript array using getJSON. The array needs to be available to all functions on a given page.
I have no trouble getting the array into the the embedded anonymous function but can't seen to get it into the parent function so it can be returned.
$bogus = rhash();
function addresslist(){
var $addresses = [];
$.getJSON ('/personal/pdo_getaddresses.php', {bogus:$bogus}
.done, function ($result){
$addresses = $result.slice(0);
console.log ('Length 01 = ' + $addresses.length)
})
console.log ('Length 02 = ' + $addresses.length)
//return $addresses;
}
The console log shows
Length 01 = 438
and
Length 02 = 0
I guess that in simple terms, I need to understand how to make the function addresslist return the data that is returned asynchronously to the anonymous function.
I've been at this all afternoon. Your advice is sincerely appreciated.