How does native Ajax commit data asynchronously?

Source: Internet
Author: User

Ajax overview

Ajax:asynchronous Javascript and XML, asynchronous JS and XML. 2001,google in order to improve the user experience of the search, put forward the googlesugguest effect, formally put forward the concept of Ajax.

Objective: To implement a local update of the content of the page without a flush without a commit-the data comes from the server.

Common applications: real-time data acquisition (e.g. stock charts), search suggestions, chat rooms, SPA

Ajax applications rely on core objects provided by the browser's underlying:

XMLHttpRequest : Used to initiate an asynchronous request to the Web server and receive a response message .

To initiate an asynchronous request step using XHR:

(1) Create XHR objects--each XHR can only send one request

VARXHR = new XMLHttpRequest ();

(2) Binding the listener function to handle every state change of XHR

Xhr.onreadystatechange = function () {}

(3) Open a connection to the Web server

Xhr.open (' GET ', ' 9.php ', true);

(4) Sending the request message body

Xhr.send (NULL);

If the Post method is in step (3), the request header format is set, i.e.

Xhr.open (' POST ', ' x.php ', true);

xhr.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded '); Modify Request message Header

Xhr.send (' K1=v1&k2=v2&k3=v3 ');

These are the basic steps of native Ajax, and the practice is: Imitation Google's search suggestions. Link Address: Search suggestions

How does native Ajax commit data asynchronously?

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.