AJAX function that reads json data. Works well.
function getUSCF() {
$.ajax({
type: "Get",
url: "assets/uscf/uscf.json",
dataType: "json",
success: function(data) {
members = [];
temp = JSON.stringify(data);
members = JSON.parse(temp);
alert (JSON.stringify(members));
//members = _.sortBy(members, o => o.Name)
//members = _.uniqBy(members,'Name');
},
error: function(){
alert("json not found");
}
});
}
But the problem is that the created "members" array of objects is not readable outside of the function getUSCF().
function initJSON() {
getUSCF(); alert(JSON.stringify(members)); // Uncaught ReferenceError: members is not defined
alert(members.length); // Uncaught ReferenceError: members is not defined
}
initJSON();