百度上說async:false,就是同步了。測試後發現不是
<script type="text/javascript">
function callAjax() {
var value = '1';
jQuery.ajax({
async:false,
url:"Handler1.ashx",
//type:"post",
success:function(msg){
value = msg;
}
});
return value;
}
$(function myfunction() {
alert(callAjax());
});
</script>
結果還是返回 1.
關鍵方法來了:
jQuery.ajax({
async:false,
url:"Handler1.ashx",
//type:"post",
success:function(msg){
value = msg;
}
}).done(function(msg){
value = msg;
});
加個done纔是真正的同步。返回後臺數據