What is the role of Ajax? A detailed introduction to Ajax functions (with examples)

Source: Internet
Author: User

This article mainly introduces the role of Ajax interpretation, so that we can more clearly use Ajax, now let's look at this article together

AJAX is a technique that can update parts of a Web page without reloading the entire page.
No flush data Read
User login, Stock Fund network
Asynchronous, synchronous
AJAX = Asynchronous JavaScript and XML (asynchronous JavaScript and XML). AJAX is not a new programming language, but a new method of using existing standards.

AJAX is the art of exchanging data with a server and updating parts of a Web page without reloading the entire page. There are many examples of applications that use AJAX: Sina Weibo, Google maps, happy net, and more. (Want to see more on the Topic.alibabacloud.comAJAX Development Manual section of the study)

Traditional development mode: each operation of the user triggers an HTTP request to return the server once, and after the server has processed it, it returns an HTML page to the user.


Ajax Development Mode: The page communicates the user's actions through the AJAX engine to the server, returns the results to the Ajax engine, and then Ajax inserts the data into the specified location.


Writing Ajax functions

1. Creating Ajax Objects

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

2. Connect to the server

Xmlhttp.open (' GET ', url,true);//Three parameters represent the method, path, synchronous, or asynchronous (true is asynchronous), respectively;

3. Send Request

Xmlhttp.send ();

4. Receive return value


Xmlhttp.onreadystatechange=function () {if (xmlhttp.readystate==4) {if (xmlhttp.status==200) {alert (' success: ' + Oajax.responsetext);} Else{alert (' failure: ' +oajax.status);}}} Encapsulated into function functions Ajax (URL, fnsucc, fnfaild) {//1. Create an Ajax object if (window. XMLHttpRequest) {var oajax=newxmlhttprequest ();} Else{var oajax=newactivexobject ("Microsoft.XMLHTTP");} 2. Connect Server//open (method, file name, asynchronous transfer) Oajax.open (' GET ', url,true);//3. Send Request Oajax.send ();//4. Receive Return oajax.onreadystatechange= function () {//oajax.readystate//browser and server, to which step the IF (oajax.readystate==4)//Read Complete {if (oajax.status==200)//Success {FNSUCC ( Oajax.responsetext);} Else{if (fnfaild) {fnfaild (oajax.status);} Alert (' Failure: ' +oajax.status ');}};}

This is the end of this article (want to see more on the Topic.alibabacloud.comAJAX User manual section of the study), there are questions can be in the message below the question.

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.