看起来我的脚本不想等待$.post调用完成。这是一个问题。以下是一些伪代码:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
// Global var, to be used everywhere in the ready scope
// Note its default value!
var test = false;
$.post('test.php',{},function(result){
if(result=='yes')
{
// This gets executed!
alert('Its true! Hurraaay!');
test = true;
}
else
{
test = false;
}
}
if(test==false)
{
// THIS gets executed, despite the fact that we set test to true!
alert('Awww....');
}
// it reaches this, showing us that there was no error!
alert('Im alive!!!');
// and a whoooole bunch of other code here...
}
</script>
如何在不挂起浏览器的情况下确保我的Post调用完成后才继续进行?希望得到一些不太复杂的方法。:)