I have a function that is pulling in data with an AJAX call. I am creating an object that I would like to access in other functions. So I would like to send the data into another global object.
Here is the currently javascript:
var foursquareMapData = [];
function MapData() {
$.ajax({
dataType: 'jsonp',
url: 'https://s3.amazonaws.com/sxsw_trending/sxsw_trending.json',
jsonp: "callback",
jsonpCallback: "sxswTrending",
success: function (data) {
//console.log(data);
// var foursquareMapData = [];
for (var i = 0; i < data.Trending.length; i++) {
var mapData = {
index: i + 1,
lat: data.Trending[i].lat,
lng: data.Trending[i].lng,
count: data.Trending[i].hereNow,
address: data.Trending[i].address
}
//console.log(mapData);
foursquareMapData.push(mapData);
}
//console.log(foursquareMapData);
}
});
}
console.log(foursquareMapData);
Pushing the 'mapData' object into the foursqureMaData doesn't seem to working. I might not be doing this properly?