The person who uses jquery for Web Front-end development believes that. the Ajax method is no stranger, and I have been using it, but I have never gotten into the meaning of each of the parameters, such as The async parameter to be mentioned today.
This parameter is explained in the official manual as follows:
Async Boolean
Default: True
By default, all requests are sent asynchronously (I. e. this is set to true by default ). if you need synchronous requests, set this option to false. cross-Domain requests and datatype: "jsonp" requests do not support synchronous operation. note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active.
Here, the default value of async is true, which is asynchronous, that is, when Ajax sends a request, it is waiting for the server to return this process, the foreground will continue to execute the script after the Ajax block until the server returns the correct result to execute success. That is to say, two threads are executed at this time, the post-request thread of the Ajax block and the script after the Ajax block. When async is set to false, the script will wait for the response from the server, and the subsequent script will be executed after the server returns the result. Before the data is returned, the Javascript script will be suspended.
This is not hard to understand, but if it and $ (document ). ajaxstart () and $ (document ). when combined with ajaxstop (), the difference between the two is big. When async is true, $ (document) is triggered by default ). ajaxstart () and $ (document ). ajaxstop (), that is, when the Ajax request is an asynchronous request, the ajaxstart and ajaxstop bound to the element will take effect. Otherwise, when async is false, that is, Ajax is a synchronous request, both methods and related ajaxcomplete will be invalid.
Turn: http://hmw.iteye.com/blog/1161724