Learn Ajax applications in three steps (Basic Ajax tutorial)

Source: Internet
Author: User
Ajax is called "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML). It is a Web page development technology used to create interactive web applications. It organically includes the following technologies: Ajax (asynchronous javas Lifecycle + XML) Definition

Representation Based on the Web Standard (Standards-based presentation) XHTML + CSS;
Use dom (Document Object Model) for Dynamic Display and interaction;
Use XML and XSLT for data exchange and related operations;
Use XMLHttpRequest for asynchronous data query and retrieval;
Use javasCript binds everything together.

Ajax applications use Web browsers that support the above technologies as the operating platform. These browsers currently include Mozilla, Firefox, Internet Explorer, opera, Konqueror, and safari.

The Ajax application consists of three steps:

1. Creation object:
VaR XMLHTTP;
If (window. activexobject) // IE
{
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest) // other browsers
{
XMLHTTP = new XMLHttpRequest ();
}

2. The response function after the request result is written:
XMLHTTP. OnReadystatechange = function ()
{
If (XMLHTTP. readystate = 2)
{
Window. Status = "submitting data ";
}
Else if (XMLHTTP. readystate = 3)
{
Window. Status = "data transfer in progress ";
}
Else if (XMLHTTP. readystate = 4)
{
If (XMLHTTP. Status = 200)
{
Window. Status = XMLHTTP. responsetext;
}
Else
{
Window. Status = "query error. Check whether the input is correct ";
}
}
Else
{
Window. Status = "querying ...";
}
}

3. Step 3: send a request
XMLHTTP. Open ("get", URL, true );
XMLHTTP. Send (null );
Reference case: http://www.51count.net/weather.htm
Now, you can write a new drop-down menu or a new message book or more advanced application.

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.