何时在jquery的ajax函数中使用async false和async true [英] When to use async false and async true in ajax function in jquery
本文介绍了何时在jquery的ajax函数中使用async false和async true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
何时使用ajax调用中使用async false或async true.就性能而言,有什么不同吗?
When to use use async false or async true in an ajax call. In terms of performance does it make any difference ?
示例:
$.ajax({
url : endpoint,
type : "post",
async : false,
success : function(data) {
if (i==1){
getMetricData(data)}
else if (i==2)
{
capture = data;
}
}
});
推荐答案
这与性能无关...
如果需要在浏览器传递给其他代码之前完成该Ajax请求,则将async设置为false:
You set async to false, when you need that ajax request to be completed before the browser passes to other codes:
<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>
这篇关于何时在jquery的ajax函数中使用async false和async true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文