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

部分摘自: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;

原文地址:https://www.cnblogs.com/xh_Blog/p/10832178.html