Introduction to Ajax

Source: Internet
Author: User

AJAX is based on open standards

AJAX is based on the following open standards:

    • Javascript
    • Xml
    • Html
    • Css

The open standards used in AJAX are well defined and supported by all major browsers. AJAX applications are independent of browsers and platforms. (It can be said that it is a cross-platform cross-browser technology).

AJAX is about better Internet applications

Compared to desktop applications, WEB applications have many advantages:

    • can have more users
    • Easier installation and Maintenance
    • Easier to develop however, applications are not always as powerful and friendly as traditional applications.

With AJAX, you can make your Internet applications more powerful (lighter, faster, and easier to use).

Today, you can start using AJAX

There is no new knowledge to learn.

AJAX is based on open standards. These standards have been used by most developers for many years.

Most Web applications can override traditional HTML forms by rewriting them with AJAX technology.

AJAX uses XML and HTTP requests

A traditional Web application submits data to a Web server (using an HTML form). After the Web server finishes processing the data, it returns a full new page to the user.

Because each time a user submits the input, the server returns a new page, and traditional Web applications tend to run slowly and become less friendly.

With Ajax,web applications, you can send and retrieve data without overloading the Web page. This is done by sending an HTTP request to the server (behind the scenes) and by using JavaScript to modify only a portion of the page when the server returns data.

XML is generally used as a format for receiving server data, although you can use any format, including plain text.

You'll learn how to do this in the next chapters of this tutorial.

PHP and AJAX

There is no AJAX server.

AJAX is a technique that runs in a browser. It uses asynchronous data transfer between the browser and the Web server, allowing the Web page to request a small amount of information from the server, rather than the entire page.

AJAX is a Web browser technology that is independent of Web server software.

However, in this tutorial, we will focus on the actual cases running on the PHP server, not how AJAX works.

To read more about how Ajax works, please visit our Ajax tutorials.

An XMLHttpRequest object makes AJAX possible.

XMLHttpRequest

The XMLHttpRequest object is the key to AJAX.

This object was available after Internet Explorer 5.5 and July 2000, but before 2005 people started discussing AJAX and Web 2.0, the object was not fully understood.

Create a XMLHttpRequest Object

Different browsers use different methods to create XMLHttpRequest objects.

Internet Explorer uses ActiveXObject.

Other browsers use JavaScript built-in objects named XMLHttpRequest.

To overcome this problem, you can use this simple piece of code:

var xmlhttp=nullif  (window. XMLHttpRequest)  {  XMLHttp=new  XMLHttpRequest ()  }Elseif (window. ActiveXObject)  {  XMLHttp=new ActiveXObject ("microsoft.xmlhttp " )  }
Code Explanation:
    1. First create a XMLHttp variable to use as a XMLHttpRequest object. Set its value to null.
    2. Then test the window. Whether the XMLHttpRequest object is available. In the new version of Firefox, Mozilla, Opera and Safari, the object is available.
    3. If available, create a new object with it: Xmlhttp=new XMLHttpRequest ()
    4. If not available, the window is detected. ActiveXObject is available. In Internet Explorer version 5.5 and later, the object is available.
    5. If available, use it to create a new object: Xmlhttp=new ActiveXObject ()

Examples of improvements

Some programmers prefer to use the latest and fastest version of the XMLHttpRequest object.

The following example attempts to load Microsoft's latest version of "Msxml2.xmlhttp", available in Internet Explorer 6, and if it fails to load, back to "Microsoft.XMLHTTP" in Internet Explorer 5.5 and later versions are available.

function Getxmlhttpobject () {varxmlhttp=NULL;Try { //Firefox, Opera 8.0+, Safarixmlhttp=NewXMLHttpRequest ();}Catch(e) {//Internet Explorer Try{xmlHttp=NewActiveXObject ("msxml2.xmlhttp"); } Catch(e) {xmlHttp=NewActiveXObject ("Microsoft.XMLHTTP"); } }returnxmlHttp;}
Code Explanation:
    1. The XMLHttp variable that is used as the XMLHttpRequest object is created first. Set its value to null.
    2. Create objects by Web standards (Mozilla, Opera and Safari): Xmlhttp=new XMLHttpRequest ()
    3. Create objects in Microsoft's way, available in Internet Explorer 6 and later: Xmlhttp=new ActiveXObject ("Msxml2.xmlhttp")
    4. If you catch an error, try an older method (Internet Explorer 5.5): xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP")

How to get requests and post requests in Ajax

  

Introduction to Ajax

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.