Native Ajax summary
HTTP protocol
Traditional requests and Ajax requests
Ajax definition
Asynchronous JavaScript and XML. Ajax is asynchronous, and JavaScript programs want to communicate directly with the server without reloading the page.
Basic process of Ajax
1. Create a request object
Function requestObject () {if (window.XMLHttpRequest) {return new XMLHttpRequest ();} else if {return new ActiveXObject ('Mxsml2.XMLHTTP');} else {throw new Error ("Could not create HTTP request object.");}}
two。 Establish request
Var request=requestObject ()
Request.open ("GET", "data.txt", true)
3. Send a request
Request.send (null)
4. Processing requests (both XML and JSON formats)
Request.onreadystatechange=function () {if (request.readyState==4) {console.log (request.status+ ":" + request.statusText);}}