I'm pretty new to js.
I'm using flask in python to create a website. What I want to do is generate a chart using googlecharts and data from an sql database. In one of my urls, I'm "jsonifying" the data and attempting to access it in js via "$.getJSON" as follows:
var males;
var females;
$.getJSON("/getstats", function(data){
for (obj of data){
males=obj.males;
females=obj.females;
}
});
But the variables' values aren't changing to equal obj.females and obj.males.
They do change to anything I assign them outside the $getJSON brackets.
I stumbled upon Variables set during $.getJSON function only accessible within function which seemed to be similar to my question; but I tried the solution within the question's "UPDATE #2" and it still didn't work.
How can I reach the values of obj.females and obj.males?