Get started with Ajax and use ajax to write helloworld

Source: Internet
Author: User

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.

Related Article

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.