$.ajaxSettings.async = false;是什么意思?

Wesley13
• 阅读 561

部分摘自:https://blog.csdn.net/jin_tk/article/details/88872821

我们都知道$.post() 和 $.get()都是异步请求的方式,但有时候不得不用,但又要同步请求时,就用到了上面写的。

方式1
//设置为同步
 $.ajaxSettings.async = false;
  $.post("url", data, function(result) {
   // 请求处理
  },"json");
  //设置回异步
 $.ajaxSettings.async = true;

使用第一种一定要注意:使用了同步后($.ajaxSettings.async = false;),及时释放掉,使用异步($.ajaxSettings.async = true;),不然会锁死资源,使得其他线程不能访问数据;

方式2:
$.ajax({
    type: "post",
    url: "url",
    data: {"reportId": rows[0].reportId},
    async: false,
    success: function(result){
        if (result.success){}else{} 
    }  
});

同步$.ajaxSettings.async = false;

异步$.ajaxSettings.async = true;

end;

点赞
收藏
评论区
推荐文章
Wesley13 Wesley13
3年前
java实体 和 xml相互转换
参考:https://blog.csdn.net/LookForDream\_/article/details/88884316(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2FLookForDream_%2Farticle%2Fdetails
Easter79 Easter79
3年前
springcloud 服务间通讯方式 Ribbon
查看Ribbon:https://blog.csdn.net/qq\_32534855/article/details/84111188(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fqq_32534855%2Farticle%2Fdetails%2F
Stella981 Stella981
3年前
InsightFace源码以及pre
一下摘自:https://blog.csdn.net/Fire\_Light\_/article/details/79602705(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2FFire_Light_%2Farticle%2Fdetails%2F7960
Stella981 Stella981
3年前
MyBatis中的@Mapper注解及配套注解使用详解
https://blog.csdn.net/phenomenonstell/article/details/79033144(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fphenomenonstell%2Farticle%2Fdetails%2F790
Wesley13 Wesley13
3年前
(使用通过混淆+自己第三方保留成功混淆)AndroidStudio 混淆打包
原文:https://blog.csdn.net/mazhidong/article/details/64820838(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fmazhidong%2Farticle%2Fdetails%2F64820838)A
Stella981 Stella981
3年前
Git本地分支和远程分支关联
转载:https://blog.csdn.net/cherishhere/article/details/52606884(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fcherishhere%2Farticle%2Fdetails%2F52606884
Stella981 Stella981
3年前
Linux用户和用户组
参考:https://blog.csdn.net/love20165104027/article/details/82386271(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Flove20165104027%2Farticle%2Fdetails%
Stella981 Stella981
3年前
185.dubbo 后台管理系统
参考:https://blog.csdn.net/weixin\_40288413/article/details/80793336(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fweixin_40288413%2Farticle%2Fdetails%2
可莉 可莉
3年前
185.dubbo 后台管理系统
参考:https://blog.csdn.net/weixin\_40288413/article/details/80793336(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Fweixin_40288413%2Farticle%2Fdetails%2
Stella981 Stella981
3年前
Android Studio从2.3升级到3.1注意事项
原文:https://blog.csdn.net/lithiumyoung/article/details/80111111(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fblog.csdn.net%2Flithiumyoung%2Farticle%2Fdetails%2F801111