“async: false"是什么意思?在 jQuery.ajax() 中做什么?
具体来说,它与默认值 ( async: true
) 有何不同?
Specifically, how does it differ from the default ( async: true
) ?
在什么情况下我想将 async
显式设置为 false
,它是否与防止页面上的其他事件触发有关?
In what circumstances would I want to explicit set async
to false
, and does it have something to do with preventing other events on the page from firing ?
有没有关系阻止页面上的其他事件开火?
Does it have something to do with preventing other events on the page from firing?
是的.
将 async 设置为 false 意味着您正在调用的语句必须在调用函数中的下一个语句之前完成.如果您设置 async: true ,那么该语句将开始执行,并且无论 async 语句是否已完成,都将调用下一条语句.
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.
有关更多见解,请参阅:jQuery ajax 成功匿名函数作用域
For more insight see: jQuery ajax success anonymous function scope