I have a function that I call which hits an API and returns a JSON
, which I am calling getData
. Inside that function is a nested function that processes the JSON
and saves it to a new variable processedData
when it's done making the request from the API.
I'd then like to return that processed JSON
, but the console is telling me it's undefined. I didn't declare the variable so it should be treated as global. Why am I still having this issue?
The code won't work with the snippet because the API is only local, but processedData
essentially looks like this: {'A': '123'}
function hitAPI() {
var getData = $.get('http://127.0.0.1:5000/myroute');
getData.done(function() {
processedData = (JSON.parse(getData['responseJSON']['data']));
});
return processedData;
};
var x = hitAPI()
console.log(x);