Ajax请求中的async:false/true的作用(ajax返回值在外部调用问题
test.html<a href="javascript:void(0)" onmouSEOver="testAsync()"> asy.js function testAsync(){ var temp; $.ajax({ async: false,//同步请求 type : "GET",url : 'tet.php',complete: function(msg){ alert('complete'); },success : function(data) { alert('success'); temp=data; } }); alert(temp); } tet.php <?php echo "here is html code"; sleep(5); ?> 说明 如上:false为同步,这个 testAsync()方法中的Ajax请求将整个浏览器锁死,只有tet.php执行结束后,才可以执行其它操作。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |