Ajax practical tutorial-Summary

Source: Internet
Author: User

After the first two tutorials, I believe that the reader has some experience with the actual Ajax application.ArticleLet's summarize the common Ajax technologies.

Use AjaxProcess:

L create an XMLHTTPRequest object based on the browser type.

L sets the callback function of the XMLHTTPRequest object and the onreadystatechange attribute.

L create a connection and open the method.

L sets the HTTP header information and the setRequestHeader method.

L request data, send method.

 

XMLHttpRequestCommon class methods and attributes:

 

OnreadystatechangeMethod:Sets the asynchronous response callback function. This function is called whenever the response status changes, specifically the value change of readystate.

OpenMethod:Create a request connection. The first parameter is the request method, post or get. The second parameter is the request URL. When it is the get method, parameters can be added to the URL. The third parameter is the asynchronous request, true is asynchronous.

SetRequestHeaderMethod:Set Request Header information. The first parameter is the header information name, and the second parameter is the header information value.

SendMethod:Send a request. When the request is Post, The send method parameter is the post parameter.

ResponsetextAttribute:Obtain the text format data returned by the server. It is generally used in callback functions.

ResponsexmlAttribute:Obtain the XML format data returned by the server. It is generally used in callback functions.

ReadystateAttribute:When an asynchronous request occurs, this value changes as the request progresses.

0: the request is not initialized;

1: The server connection has been established;

2: The request has been received;

3: The request is being processed;

4: The request is complete and the response is ready.

StatusAttribute:Request result.

200: "OK"

404: Page not found

 

JavascriptXML operationsCommon methods and attributes:

 

GetelementsbytagnameMethod:Obtains an element based on the element (TAG) Name and returns an array. An array is returned even if the element appears only once, except that the array has only one element. The parameter is the element name.

GetelementbyidMethod:Obtain the element by ID. The parameter is the element ID. Because the ID is unique, this method returns only one element.

GetattributeMethod:Obtains an attribute value of an element. The parameter is the property name.

SetattributeMethod:Set an attribute value of an element. The parameter is the property name.

CreateelementMethod:Create an element. The parameter is the element name. If it is successfully created, this method returns the Element Object.

AppendchildMethod:Insert child elements. Parameters are element objects created using the createelement method.

RemovechildMethod:Delete child elements. The parameter can be an element object obtained through the getelementsbytagname or getelementbyid method.

FirstchildAttribute:Obtain the first child element.

ChildnodesAttribute:Array of child elements. For example, childnodes [I] obtains the subelement I; childnodes. Length obtains the number of all subelements.

NodevalueAttribute:Obtain/set element values. Note the differences between element values and attribute values.

When using XML, you must pay special attention to the encoding and resolution formats of the client and server. If the client wants to obtain data in XML format, the server must set contenttype to "text/XML". In addition, the XML data format transmitted during interaction must be standardized. Otherwise, the retrieval may fail.

This is the basic knowledge of Ajax, which is sufficient to meet general requirements.

In fact, Ajax is sometimes not so perfect. Now, the popular online customer service, chatting on the webpage, Xiao Cai thinks that AJAX can be used to achieve the push effect, but it is actually not possible, data can only be retrieved from the server without interruption.

This tutorial is for reference only! If you have any errors, please correct them!

Now, the tutorial is over! Welcome to join me! Wish readers a pleasant learning experience!

 

 

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.