何时使用在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;
}
}
});
Run Code Online (Sandbox Code Playgroud)
Ami*_*aqi 37
这与表现无关......
在浏览器传递给其他代码之前需要完成ajax请求时,将async设置为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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
87279 次 |
最近记录: |