ajax方法中有一个属性async是用于控制同步和异步请求的,async为true时是为异步请求(默认为true),false时是同步请求。
当async为 true 时,ajax请求是为异步请求,此时其他ajax方法也是可以进行的,不影响请求的进行,但当async为 false 时,ajax请求为同步请求,此时其他ajax方法是得当这个ajax请求执行完毕后其他请求才能继续进行,这时页面时相当于暂停加载,所以一般情况我们都是使用异步请求。
在我个人做项目过程中,有时使用了false同步请求时会出现前端警报:
[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help, check https://xhr.spec.whatwg.org/.
这就是由于使用了同步请求。