This gives me the content of a file, in an alert box. As long as the alert is inside the get-functions block it's working fine:
var allActivities = [];
$(document).ready(function() {
$.get('./activities.txt', function(result) {
currentActivity = result.split(",");
allActivities.push(currentActivity);
alert(allActivities); // Alert box returns correct results
});
}
But when I move the alert outside of the get-function scope, the alert box is empty. I'm guessing I have messed up with some scopes, but I can't figure out what.
var allActivities = [];
$(document).ready(function() {
$.get('./activities.txt', function(result) {
currentActivity = result.split(",");
allActivities.push(currentActivity);
});
alert(allActivities); // Alert box is empty
}
I need the array allActivities
to be global so that I can access it outside of the .get function. So I need the last code example to work. In other words, the last code example needs to alert the content.