I am trying to use the variables that I set within my $.get function outside of the function itself.
Here is the $.get:
$.get("process/getTotalSales.php", function (data) {
var obj = JSON.parse(data);
let prodLine = obj.map((el) => "'" + el.product_line + "'");
let total = obj.map((el) => el.sum);
});
I’m trying to access the variables “prodLine” and “total” outside of the function above.
I tried to wrap the $.get inside of a function, like this:
function getTotals() {
$.get("process/getTotalSales.php", function (data) {
var obj = JSON.parse(data);
let prodLine = obj.map((el) => "'" + el.product_line + "'");
let total = obj.map((el) => el.sum);
console.log(prodLine);
});
}
Then call the function:
getTotals();
Using the getTotals function, I can see prodLine in the console. I just need to be able to access it.
How can I make this happen?