What is Ajax? AJAX: "Asynchronous JavaScript and xml" Chinese meaning: Asynchronous JavaScript and XML.

Source: Internet
Author: User

Refers to a web development technique that creates an interactive Web application.

AJAX is not an acronym, but a noun created by Jesse James Gaiiett.

Does not refer to a single technology, but organically utilizes a range of related technologies:

The representation of the Web Standard (standards-based Presentation) Xhtml+css,

Use the DOM (Document Object Model) for dynamic display and interaction,

Using XML and XSLT for data exchange and related operations,

Use XMLHttpRequest for asynchronous data querying and retrieval.

AjaxAdvantages

Lajax is essentially a browser-side technology Lajax technology is the main purpose of the local exchange between the client and server data L The main character of this technology, XMLHttpRequest, is the ability to re-load the entire layout to update the data, that is, the so-called refresh Without Reload (light refresh) L communicates with the server, completely through JavaScript I use the XMLHttpRequest itself to transmit a small amount of data, so the response will be faster, but also let the network program more like a desktop application Lajax Is the use of JavaScript in the background to quietly help you to the server to the data, and finally by JavaScript or DOM to help you render the results, because all the actions are made by JavaScript, so eliminate the hassle of Web page overloading, users can not feel the pain of waiting

1.GET mode

1.1 Setting parameters

Xhr.open ("GET", "Getareasbyajax.ashx?isajax=1", true);

1.2GET Way request can set browser not to use cache
Xhr.setrequestheader ("If-modified-since", "0");

1.3 Send: Xhr.send (null);//get mode

2.POST mode:
1.1 Setting Parameters: Xhr.open ("POST", "getareasbyajax.aspx", true);
1.2 Add request Header: Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded");

1.3 Send: Xhr.send ("isajax=1&na=123");//post mode

Using XMLHttpRequest Objects Asynchronously

When you use an XMLHttpRequest object asynchronously, you must use the: onReadyStateChange event.

The usage pattern should be:

1. Create the object;-new2. Set the ReadyStateChange event to trigger acallback function; -onreadystatechagne3. Open a request;-open4. send a request;-send

Note: Check the ReadyState property in the callback function to see if the data is ready (equals 4).

If you are not ready, check again at intervals. Because the data is not finished downloading, we cannot use its properties and methods. If you are ready, proceed to execution; Lreadystate Property

The ReadyState property indicates several states in which the XMLHttpRequest object is in the process of sending/receiving data. The XMLHttpRequest object undergoes 5 different states.

• 0: Uninitialized. Object has been created, but not initialized yet, the open method has not been called; • 1: Opened. The object has been created and initialized, but the Send method has not been called; 2: Sent. The Send method has been called, but the object is waiting for the status code and header to return; • 3: Receiving. Some data has been received, but the properties and methods of the object cannot be used, because the state and response headers are incomplete; 4: Loaded. What happens if the server goes wrong when all the data is received lajax the request server? L Programming Common error XMLHttpRequest casing is not correct; • Write more pairs of parentheses:

Correct: Xhrobject.onreadystatechange =getdata;

Error: Xhrobject.onreadystatechange =getdata ();

It must be clarified that in javascript:

• If there is a parenthesis after the function name, the meaning is to assign the return value of the function to the variable to the left of the equal sign; • Without parentheses, it is the variable that assigns the function itself to the equal sign.

What is Ajax? AJAX: "Asynchronous JavaScript and xml" Chinese meaning: Asynchronous JavaScript and XML.

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.