订单继是我的代码:的jQuery:执行
$(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
}
});
所需执行的顺序:
线1
2号线(具有值相同,在1号线)
第3行
实际执行顺序:
2号线(价值:未定义)
3号线
1号线(修正值)
如何控制这些线以获得与正确的价值观所需要的行执行的顺序?
集异步为假 –
@SenthilKumar:永远不要那样做。 – Bergi
@Bergi,你能告诉我为什么它不好? –