Here's my json file:
{
"info": {
"title": "LRR Test map",
"width": 50,
"height": 50
}
}
And here's my JavaScript code:
var mapInfo = $.getJSON('levels/test.json').done(function(data){mapInfo = data.info;});
alert(mapInfo.title);
Problem is, I get an alert labeled undefined
. Well, when I open up my developer console (I'm on Chrome) and type in mapInfo
I get this output:
Object {title: "LRR Test map", width: 50, height: 50}
And when I type in alert(mapInfo.title);
it does alert my Lrr Test map
.
Why can I access my variable through developer console, but I cannot call it out in my code? This is really uncommon for me, and appeared for the first time in my quite large project.