我有以下代码,出于某种奇怪的原因,事件发生的顺序对我来说没有意义。无论如何,我可以使它按顺序排列吗?
var vm_good = false;
console.log("Before", vm_good);
$.post("./ajax/call_price", {id: product_id}, function(data){
$.each(data, function(key, value){
$(".unit-price span").html(value);
});
vm_good = true;
console.log("Inside", vm_good);
enableNext();
}, 'json');
console.log("After", vm_good);
控制台窗口上的结果是:
>Before false
>After false
>Inside true
>window.vm_good // I called it manually after the page loaded
>>true