Ajax study Note 1

Source: Internet
Author: User

What Is Ajax?

Ajax is "Asynchronous JavaScript + XML" (Asynchronous JavaScript and XML), which is a Web page development technology used to create interactive web applications. It can quickly obtain the required data and content from the server, and achieve local refreshing so that users can better browse the website. When there is no Ajax, the webpage submission form must be waited and refreshed. At this time, the user must wait for the response from the server, and the user cannot do anything else on the current page. With Ajax, users do not need to wait when submitting a form. They can browse other things on the page. After the form is submitted, the server can quickly return the required data and webpages, the webpage does not need to be refreshed.

What can Ajax do?

When there is no Ajax, when we perform form verification, we must enter it before submitting the page to check whether the information is legal and valid, and the page must be refreshed, in this way, the user experience is very poor. The information entered by the user through hard work is found to be incorrect and illegal only when submitted, which leads to a poor user experience. After Ajax technology is used, checking the form information can quickly obtain information from the server without refreshing it, making it very convenient for users to use it. AJAX can also achieve partial refresh, just like Google Maps.

Next, let's learn how to use Ajax?

Before using Ajax, you must have a good grasp of the XMLHTTPRequest object, because Ajax is used around the XMLHTTPRequest object. Ajax usage:

(1) first create the XMLHTTPRequest object

var xmlhttp;if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }

(2) Call the XMLHttpRequest method open (), and send ()

XMLHTTP. Open ("get", "URL path", true); XMLHTTP. Send ();

 



(3) The server returns responsetext
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;

 


The value returned by the server is assigned to the tag of mydiv.
However, the HTTP status must be determined, and the code is as follows:
xmlhttp.onreadystatechange=function()  {  if (xmlhttp.readyState==4 && xmlhttp.status==200)    {    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;    }  }

 

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.