How {async:false} Works In Jquery Ajax Request?
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?
Solution 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.
Solution 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.
Post a Comment for "How {async:false} Works In Jquery Ajax Request?"