示例:
$.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>