Summary of Ajax technology

Source: Internet
Author: User

Ajax
First, let's talk about Synchronous interaction and Asynchronous interaction.
The concept of writing is rather abstract. So what is asynchronous and synchronous?
Synchronization means that I have sent the data. I must wait until the receiver receives the data before sending the next data.
Asynchronous means that I have sent the data, and the receiver will receive it. I don't have to watch it and send the next data. You just need to tell me after sending it.
The entire process of Ajax is Asynchronous javascript and xml.
The technology that allows the browser to communicate with the server without refreshing the current page is called Ajax.
What is better for Ajax models than traditional models?
1. The number of required pages is small and the performance is high
2. In the same scenario, the Ajax interaction data is small and our bandwidth requirements are reduced.
3. Low Pressure on the server
Ajax technologies, such as flash, iframe, and xmlhttprequest, can achieve Asynchronous interaction.

The following describes how AJAX works.
There is an Ajax engine between the client and the server. When Ajax is used for interaction, the Ajax engine and the javascript engine are widely used.

AJAX is not a technology. It contains javascript, xHtML, css, Dom, xmlhttprequest, etc.

Ajax defects:
1. ajax is not applicable to any scenario. It depends on the support of the browser. The client and server do not refresh the page, which may cause a large amount of cached data on the page. Users often cannot figure out whether the data is new or old, this requires you to come up with a special tip, and the browser also loses the forward and backward functions. In addition, Ajax does not support media streams well, and does not support some handheld devices well. It can only support Ajax Asynchronous interaction.

Next we will focus on Xmlhttprequest
Xmlhttprequest is a javascript Object used to implement requests and responses between the client and the server, and is the core object of Ajax.

The following describes the Ajax implementation steps:
1. Create an Xmlhttprequest object
2. register the listener
2.1 obtain the communication status of the server
2.2 obtain the server response status code
3. Establish a connection
4. Send a request




Register a listener
Use the onreadystatechange attribute of the xmlhttprequest object to listen to the Communication Status of the server.
Use the readyState attribute of the xmlhttprequest object to obtain the server response status.
Use the satus attribute of the xmlhttprequest object to obtain the first three status codes of the response header.
Establish a connection between the client and the server
The openmethod, url, and asynch methods of the xmlhttprequest object are used.
The request type can be get or post.
Send request data to the server
Use the xmlhttprequest object send) method. In the post mode, send can send data, but the request header information must be set to content-type.
Use

When Ajax is used for Asynchronous interaction. The client receives data from the server:
Use the responseText attribute of the xmlhttprequest object: whether the accepted content is text content or html code
When the client receives the response from the server, the data format is xml.
When the client receives the response from the server, the data format is XML.
* Server side:
* Set the response header to "Content-Type" text/xml"
Response. setContentType ("text/xml; charset = UTF-8 ");
* Manually constructed xml format data
* Data comes from the query database and is encapsulated in javabean, List, Map, and Array sets.
* How to convert contents of javabean, List, Map, and Array to xml data formats?

* Client:
* Use the responseXML attribute of the XMLHttpRequest object: The received format is XML.
* Parse XML format data using DOM

This article is from the "session" blog, please be sure to keep this source http://7720365.blog.51cto.com/7710365/1290200

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.