I'm trying to pass data that I've received from a JSON file to a later point in my code. This is the part that receives the JSON data:
function getLeft(x){
var result
$.get('info.json',{},function(data){
result = data.doors[x].left;
console.log(result);
return result;
});
}
and this is the part that uses it:
if(getLeft(0) == true){
alert("door is locked");
}
Through debugging I know that result from the getLeft function is returning the correct data, but actually checking the data of getLeft(0) comes out as undefined. I've googled this, but I'm still really confused about why it does this, or how to fix it. I'm really new to jQuery and Javascript so any help would be greatly appreciated.