What does “async: false” do in jQuery.ajax()?

后端 未结 7 1634
北海茫月
北海茫月 2020-11-22 01:47

Specifically, how does it differ from the default ( async: true ) ?

In what circumstances would I want to explicit set async to fals

7条回答
  •  时光说笑
    2020-11-22 02:38

    From

    https://xhr.spec.whatwg.org/#synchronous-flag

    Synchronous XMLHttpRequest outside of workers is in the process of being removed from the web platform as it has detrimental effects to the end user's experience. (This is a long process that takes many years.) Developers must not pass false for the async argument when the JavaScript global environment is a document environment. User agents are strongly encouraged to warn about such usage in developer tools and may experiment with throwing an InvalidAccessError exception when it occurs. The future direction is to only allow XMLHttpRequests in worker threads. The message is intended to be a warning to that effect.

提交回复
热议问题