In-depth introduction to Ajax technology

Source: Internet
Author: User
Tags xslt

Ajax Full name: (Asynchronous JavaScript + XML)

Representation Based on the Web Standard (Standards-based presentation) XHTML + CSS;

It mainly includes the following technologies:
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 to bind everything together.

Similar to DHTML or lamp, Ajax does not refer to a single technology, but organically utilizes a series of related technologies.

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. However, opera does not support XSL format objects or XSLT.

Basic applications:

The method for creating XMLHttpRequest is as follows:

The XMLHttpRequest class is first introduced by Internet Explorer as an ActiveX object and is called XMLHTTP. Later, Mozilla, Netscape, Safari, and other browsers also provided the XMLHttpRequest class, but they had different methods to create the XMLHttpRequest class.

For Internet Explorer:

Xmlhttp_request = new activexobject ("msxml2.xmlhttp. 3.0"); // 3.0 or 4.0, 5.0

Xmlhttp_request = new activexobject ("msxml2.xmlhttp ");

Xmlhttp_request = new activexobject ("Microsoft. XMLHTTP ");

XMLHTTP versions may be different in different Internet Explorer browsers. To better be compatible with different versions of Internet Explorer browsers, we need to create the XMLHttpRequest class based on different versions of Internet Explorer browsers.CodeIt is the method for creating the XMLHttpRequest Class Based on Different Internet Explorer browsers.

For Mozilla, Netscape, Safari, and other browsers

The method for creating XMLHttpRequest is as follows: xmlhttp_request = new XMLHttpRequest ();

Some Mozilla browsers may not work properly if the server's response does not contain the XML mime-type header. To solve this problem, if the server response header is not text/XML, you can call other methods to modify the header.

Xmlhttp_request = new XMLHttpRequest ();

Xmlhttp_request.overridemimetype ('text/xml ');

In practical applications, to be compatible with browsers of different versions, the method for creating the XMLHttpRequest class is generally written as follows:

Try {

If (window. activexobject ){

For (VAR I = 5; I --){

Try {

If (I = 2 ){

Xmlhttp_request = new activexobject ("Microsoft. XMLHTTP ");}

Else {

Xmlhttp_request = new activexobject ("msxml2.xmlhttp." + I + ". 0 ");

Xmlhttp_request.setrequestheader ("Content-Type", "text/XML ");

Xmlhttp_request.setrequestheader ("charset", "gb2312 ");}

Break ;}

Catch (e ){

Xmlhttp_request = false ;}}}

Else if (window. XMLHttpRequest)

{Xmlhttp_request = new XMLHttpRequest ();

If (xmlhttp_request.overridemimetype)

{Xmlhttp_request.overridemimetype ('text/xml ');}}}

Catch (e) {xmlhttp_request = false ;}

Sent request

You can call the open () and send () Methods of the HTTP request class as follows:

Xmlhttp_request.open ('get', URL, true );

Xmlhttp_request.send (null );

The first parameter of open () is the HTTP Request Method-Get, post, or the method you want to call supported by any server. According to HTTP specifications, this parameter must be capitalized; otherwise, Some browsers (such as Firefox) may not be able to process requests.

The second parameter is the URL of the Request page.

The third parameter sets whether the request is in asynchronous mode. If it is true, the JavaScript function will continue to be executed without waiting for the server to respond. This is "A" in "ajax ".

Process the data obtained from the server:

There are two ways to obtain the data:

(1) return the server response in the form of a text string

(2) return a response as an xmldocument object

 

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.