Differences between asynchronous and synchronous Ajax

Source: Internet
Author: User

Request methods include GET and POST: GET, which are the most common HTTP requests. The GET request directly follows the URL and starts with a question mark. (Window. location. search is used in JS ). The parameters can be encoded using encodeURIComponent. Usage:
Var EnParam = encodeURIComponent (param );

The URL can only be about 2 k in length, that is, 2048 characters. When AJAX requests are made using GET, the cached page may not appear correctly. Generally, the random parameter value is added. ajax. send (null ).

POST

It is used to submit data to the server.

You need to extract and convert the values in the form into strings and connect them with the & Symbol (same as the GET parameter). Submit 2 GB of data volume. Use ajax. setRequestHeader ('content-type', 'application/x-www-form-urlencoded') to process the submitted string. ajax. send (strings). This strings indicates the content to be submitted in form, for example, a = 1 & B = 2.


Synchronous and asynchronous:

In the ajax. open method, 3rd parameters are set to synchronous or asynchronous. Js class libraries such as prototype are generally asynchronous by default, that is, set to true. First, in the case of synchronization, js will wait for the request to return and get the status. Onreadystatechange event handler is not required. While asynchronous processing requires onreadystatechange event processing, and the value is 4, and then the following content is processed correctly.

(Note: ajax in the text indicates the XMLHTTP request object .)

Related Article

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.