I have the following which creates an array (of sorts!):
var combined = [];
function slides(){
$.ajax({
type: "GET",
url: '../queries/get_all_slides.php',
cache: false,
dataType: "json",
success: function(reply){
$.each(reply.slides, function(a, b){
combined.push({"src":b.slide_banner,"title":b.slide_title});
});
}
});
}
slides();
console.log(combined);
in the console I get:
Array []
0: Object { src: "1712681532_1920x1080.jpg", title: "Title 1" }
1: Object { src: "1713922664_1920x1080.jpg", title: "Title 2" }
length: 2
But when I try to get the values back, I get nothing:
function test(){
$.each(combined, function(x,y){
console.log("y " + y);
console.log("x " + x);
$.each(x, function(a,b){
console.log("hello 3");
console.log("b " + b[0]);
});
});
}
test();
slidesfunction is an ansynchronous function. You should refer to this answer for a solutionsuccesscallback (at least in this AJAX operation structure, there are other structures as well).