1. Written in front:
Read Request:
With certain HTML, CSS, JavaScript, JSON basics
2. What is Ajax
Ajax: "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML) refers to a web development technology that creates interactive Web applications.
3. Why use Ajax
In the Dynamic Web development technology, the client (usually the browser) and the server data interaction is very frequent, how to save network resources, provide a good user experience is very critical. Ajax using asynchronous request, so that without refreshing the entire page can be implemented with the background data interaction, thus updating content ...
4. How to use native Ajax
The key point of using AJAX technology falls on the XMLHttpRequest (note: IE5, IE6 use ActiveXObject) object, so it is critical to make good use of this object
Attention:
function LoadData () {//Create XMLHttpRequest object var xmlhttprequestobj = {};
Creates a JSON object that transmits JSON-formatted data to the server-side Var jsonobj = {}; if (window.
XMLHttpRequest) {//ie7+, Firefox, Chrome, Opera, Safari xmlhttprequestobj =new XMLHttpRequest ();
else {//IE6, IE5 xmlhttprequestobj =new activexobject ("Microsoft.XMLHTTP");
//When the request state changes, the Xmlhttprequestobj. onReadyStateChange method xmlhttprequestobj. onreadystatechange = function () {
if (xmlhttprequestobj. readyState = = 0) {Alert ("open () function not executed");
else if (xmlhttprequestobj.readystate = 1) {Alert ("open () function executed, send () function not executed"); else if (xmlhttprequestobj.readystate = = 2) {Alert ("Send () function executed, header and status code can get")} else if (xmlhttprequestobj.
ReadyState = = 3) {Alert ("head received, analytic response body");
else if (xmlhttprequestobj.readystate = 4) {Alert ("request Complete");
If (Xmlhttprequestobj.status =) {Alert ("The response is ready, deserializing the JSON object fills the data to the page"); } ELSE if (Xmlhttprequestobj.status = =) {Alert ("page missing");
else {Alert ("service exception"); //method: Request method: Get, POST, put, DELETE ...
URL: The requested address ASNYC: whether to use asynchronous Xmlhttprequestobj.open ("method", "url", async); Set the request header, the POST request format needs to be loaded, others do not need Xmlhttprequestobj.setrequestheader ("Content-type", "application/x-www-form-urlencoded
");
Request data, parameter is jsonobj JSON object Xmlhttprequestobj.send (jsonobj); }
The above article on the AJAX request technology is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.