Following's my code :
$(document).on("click",".ball_link", function makeDiv(){
function fetchLevels(){
$.getJSON('fetch_level.php',{level: clicked_ball}, function(data) {
$.each(data, function(i,name) {
alert(name.level_id); //Line 1
});
});
}
fetchLevels();
alert(name.level_id); //Line 2
while (//some condition){
alert("hi 2"); //Line 3
}
});
Required order of execution :
Line 1
Line 2 (with value same as that in line 1)
Line 3
Actual order of execution :
Line 2 (value : undefined)
Line 3
Line 1 (correct value)
How do I control the order of execution of these lines to get the required lines with right values?