How {async:false} works in jQuery AJAX request?

隐身守侯 提交于 2019-12-20 02:05:06

问题


I know why and how to use {async:false} in jQuery AJAX request.

But what I need is how this works synchronously? What is the magic behind this?


回答1:


Because the native XMLHTTPRequest object provides the possibility to make synchronous requests:

async
An optional boolean parameter, defaulting to true, indicating whether or not to perform the operation asynchronously.

You can assume that it does that by pausing the thread in which JS runs.




回答2:


My best guess, is that when async is false, then it will wait until the readyState is set to DONE, which as defined by the W3, is:

The data transfer has been completed or something went wrong during the transfer (e.g. infinite redirects).

So basically when the request is completed, it will continue on.



来源:https://stackoverflow.com/questions/22386591/how-asyncfalse-works-in-jquery-ajax-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!