何时在ajax调用中使用async false或async true.在性能方面有什么区别?
示例:
$.ajax({ url : endpoint,type : "post",async : false,success : function(data) { if (i==1){ getMetricData(data)} else if (i==2) { capture = data; } } });
解决方法
这与演出无关
当您需要在浏览器传递给其他代码之前需要完成ajax请求时,将异步设置为false:
<script> // ... $.ajax(... async: false ...); // hey browser! first complete this request,// then go for other codes $.ajax(...); // Executed after the completion of the prevIoUs async:false request. </script>