In the code below i am trying to run loop_the_table
function after ajax_call
has finished. My code is:
function ajax_and_loop(){
ajax_call(function(){ loop_the_table();});
}
function ajax_call(callback){
$(document).ready(function(){
$.getJSON('php_side.php', function(data) {
$(data).each(function(key, value) {
value = value.toString();
res = value.split(',');
array_of_people_already_suscribed[row][column++] = res[0];
array_of_people_already_suscribed[row][column++] = res[1];
array_of_people_already_suscribed[row][column] = res[2];
row++;
column = 0;
});
});
if (typeof callback === "function") {
callback();
}
});
}
function loop_the_table(){
console.log("The row is "+row);
for(var i = 0; i < row; i++){
console.log("kalispera oli mera");
console.log(array_of_people_already_suscribed[i][0]);
console.log(array_of_people_already_suscribed[i][1]);
console.log(array_of_people_already_suscribed[i][2]);
}
}
Cosnidering ajax_and_loop
gets called from index.html
, what is wrong with the code? (It does not finish first ajax_call
function before calling loop_the_table
as it is)