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?