A new understanding of the $. Ajax method in jquery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.