Im trying to fill my array with data from a getjson/ajax command but for some reason the array is empty outside the function.
this is my code:
$.ajax({
url: instagramUrl,
dataType: 'json',
async: false,
data: access_parameters,
success: function(data) {
if(data.data.length > 0) {
for (var key in data.data ){
photo_container.push(data.data[key]);
console.log(photo_container); <--- filled array
}
}
}
});
console.log(photo_container); <--- empty array
I found that async: false should solve this problem but i cant make it work i allready tried getjson before this and this didnt work either.
$.ajaxSetup({
async: false
});
doesnt work either :(
If someone knows the answer please let me know! Thanks!