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

后端 未结 7 1573
北海茫月
北海茫月 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:34

    Does it have something to do with preventing other events on the page from firing?

    Yes.

    Setting async to false means that the statement you are calling has to complete before the next statement in your function can be called. If you set async: true then that statement will begin it's execution and the next statement will be called regardless of whether the async statement has completed yet.

    For more insight see: jQuery ajax success anonymous function scope

提交回复
热议问题