My MWE data.js looks like this:
var data = [];
function initdata(){
$.ajax({
...
success: function(data){
data.push("test");
},
...
});
}
$(document).ready(function(){
initdata();
console.log(data.length);
console.log(data[0]);
}
But the console says, data.length
is 0
and data[0]
is undefined
. How can I access data from an ajax function in another function?