I'm trying to include an external JSON file in a script:
var locations;
$.getJSON(themeUri + '/resources/location.json', function(result){
locations = result;
console.log(locations); // it shows right results.
});
console.log(locations); // undef
locations
isn't in the global scope. As I read, this is because async function.
So, I tried:
var locations;
function jsonCallback(result){
locations = result;
}
$.getJSON(themeUri + '/resources/location.json', jsonCallback);
Doesn't work neither. How can I put the JSON contents in a global variable?