I have the following Javascript function that should return an array of groups that are in database. It uses $.getJSON() method to call get_groups.php which actually reads from the database.
function get_groups() {
var groups = [];
$.getJSON('get_groups.php', function(response) {
for (var i in response) {
groups.push(response[i]);
}
}
return groups;
}
Unfortunately, this function does not work as expected because groups.push(response[i]);
does not fill the var groups = []; (as I understand it fills some other groups array, probably the global one).
Assuming that I don't want to have a global groups variable, how would you solve this problem ?