1: Ajax is considered to be (abbreviated as Asynchronous JavaScript and XML ). Currently, Ajax is a technology that allows the browser to communicate with the server without refreshing the current page.
Ajax: a way to communicate with the server without refreshing the entire page. 2. Compile a helloworld applet using Ajax and pop up the content in the text box in the hyperlink.
<SCRIPT type = "text/JavaScript"> window. onload = function () {// 1: Obtain node A and add the onclick () function document to it. getelementsbytagname ("A") [0]. onclick = function () {// 2: Create an XMLHTTPRequest object var request = new XMLHttpRequest (); // 3: Prepare the data to send the request: URL var url = This. href; // 4: Call the Open Method Request of the XMLHTTPRequest object. open ("get", URL); // 5: Call the send Method Request of the XMLHTTPRequest object. send (null); // 6: add the onreadystatechange response function request to the XMLHTTPRequest object. onreadystatechange = function () {// determine whether the response is complete: when the value of readystate of XMLHttpRequest is 4, // alert (request. readystate); If (request. readystate = 4) {// determine whether the response is available. When the status attribute value of XMLHttpRequest is 200, if (request. status = 200 | request = 304) // 8: print the response result alert (request. responsetext) ;}} return false; // do not change. Cancel the default click behavior };} </SCRIPT> 3: Create an XMLHTTPRequest object
VaR request = new XMLHttpRequest ();
4: XMLHttpRequest Method
5: Attributes of XMLHttpRequest
? Status-each response sent by the server also carries the header information. The three-digit status code is the most important header in the response sent by the server and is part of Hypertext Transfer Protocol. -Common status codes and their meanings :? 404 cannot find the page (notfound )? 403 forbidden access (Forbidden )? 500 internal server error (internalservice error )? 200 is everything normal (OK )? 304 not modified (notmodified)-In the XMLHTTPRequest object, the status codes sent by the server are saved in the status attribute. By comparing the value with 200 or 304, you can ensure that the server has sent a successful response.