What is Ajax

Source: Internet
Author: User
Tags http request object model xslt microsoft outlook

Do not say what Ajax is, we talk about Ajax good, like user registration in advance to prompt the user is registered, this can not only reduce the user's time, a better embodiment of the user experience, on a desktop application of the feeling, the following to see what is Ajax bar.

Xmlhttp_request = new XMLHttpRequest ();
Xmlhttp_request.overridemimetype (' Text/xml ');

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

try{
if (window. ActiveXObject) {
for (var i = 5; i; 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 ("Content-type", "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;}

To send the following,
Xmlhttp_request.open (' Get ', URL, true);
Xmlhttp_request.send (NULL);

After you create a XMLHttpRequest class with JavaScript to send an HTTP request to the server, decide what you want to do when you receive a response from the server. This tells the HTTP request object which JavaScript function to use to handle the response. You can set the object's onReadyStateChange property to the name of the JavaScript function you want to use, as follows:

Xmlhttp_request.onreadystatechange =functionname;

FunctionName is a function name created with JavaScript, be careful not to write functionname (), and of course we can create JavaScript code directly after onreadystatechange, for example:

Xmlhttp_request.onreadystatechange = function () {
//JavaScript code snippet
};
The
checks the status of the request first. The function can handle the response only if a full server response has been received. XMLHttpRequest provides a ReadyState property to determine the server response. The value of the

ReadyState is as follows:

0 (uninitialized)

1 (loading)

2 (load complete)

3 (in interaction)

4 (complete)

So the function can handle the response only if a full server response has been received by readystate=4. The specific code is as follows:

if (http_request.readystate = = 4) {//Receive full server response}
else {//No full server response}

when readystate=4 , a full server response has been received, and then the function checks the status value of the HTTP server response. Full state values can be found in the documentation for the document. When the HTTP server responds with a value of 200, it indicates that the status is normal.

After checking the status value of the request and the HTTP status value of the response, you can handle the data that was obtained from the server. There are two ways to get this data:

Ajax is not a technology. It is actually a combination of several powerful technologies that have been in their field. Ajax Mixed up:
* Based on XHTML/CSS
* Dynamic display and interaction by Dom (Document Object Model)
* Data exchange and processing through XML and XSLT
* Use JavaScript to integrate the above technologies
The full name of Ajax is: Asynchronousjavascript+xml

Definition of 2.Ajax:
Ajax is not a technology, it is actually several technologies, each of which has its own uniqueness, and together it becomes a powerful new technology.

3.Ajax includes:
XHTML and CSS
Use the Document Object Model (Documentobjectmodel) for dynamic display and interaction
Data interaction and manipulation using XML and XSLT
Using XMLHttpRequest for asynchronous data reception
Use JavaScript to bind them together

The latest buzzword in web development is the essence of "a new facelift".

Ajax (Asynchronousjavascriptandxml) is a combination of Java technology, XML and JavaScript, and other programming techniques that allow developers to build web-based applications based on Java technology, and break the practice of using page overloading.

Ajax is a Web application development method that uses client script to exchange data with a Web server. This way, Web pages can be updated dynamically without interrupting the interactive process. With Ajax, users can create a direct, highly available, richer, more dynamic Web user interface that is close to local desktop applications.

asynchronous JavaScript and XML (AJAX) are not new technologies, but rather a method that uses several existing technologies-including cascading style sheets (CSS), JavaScript, XHTML, XML, and Extensible Style Language Transformations (XSLT). Develop Web applications that look and operate like desktop software. All of the components that implement Ajax have existed for many years. Adaptivepath's user Experience strategy department head and founder partner Jessejamesgarrett coined the term in an article published on the Adaptivepath website this February.

The term asynchronous refers to the way AJAX applications communicate with host servers. If you use the old mode, the Web browser updates the current window whenever the user performs some action and requests new data from the server.

If you use an AJAX asynchronous Pattern, the browser does not have to wait for the user to request the operation, or update the entire window to display the newly acquired data. As long as the data is sent back and forth in XML format, JavaScript code running in the browser can be contacted with the server. JavaScript code can also add a style sheet to the retrieved data and then display it on a portion of an existing page.

Google's Gmail and GoogleMaps are among the most common examples of consumer-facing applications. In Gmail, Ajax is responsible for how to open a thread session to display the text content of different messages. In Maps, Ajax allows users to drag and roll maps in a seemingly seamless way.

and Yahoo's Flickr photo sharing app and Amazon's A9 search engine. In addition, Yahoo's new web mail Service may soon attract the attention of Ajax supporters, based on the technology that Yahoo acquired after Oddpost.

These UI are fully used in the background channel, but also by some developers called "Web2.0", and led to an interest in AJAX applications soared.

However, AJAX application software vendors are increasingly targeting businesses. For example, Scalix's webaccess e-mail application is actually more like Outlook than Microsoft Outlook's own Web mail interface.

However, the application field of AJAX applications has certain limitations. Because they take advantage of some of the latest web technologies, they can only run in some Web browsers-but Ajax is becoming more and more suitable for browsers.

Ajax

Ajax, asynchronous JavaScript and XML, is a Web application development method that uses client script to exchange data with a Web server. This way, Web pages can be updated dynamically without interrupting the interactive process. With Ajax, you can create a direct, highly available, richer, more dynamic Web user interface that is close to local desktop applications.

Ajax processing Process

An AJAX interaction begins with a JavaScript object called XMLHttpRequest. As the name implies, it allows a client script to execute the HTTP request and will parse an XML-formatted server response. The first step in the AJAX process is to create a XMLHttpRequest instance. Use the HTTP method (get or post) to process the request and set the target URL to the XMLHttpRequest object.

Now, remember how Ajax is first in the asynchronous processing state? When you send an HTTP request, you do not want the browser to hang up and wait for the server to respond, instead, you want to continue to interact with the user's interface through the page and process them after the server response has actually arrived. To do this, you can register a callback function with XMLHttpRequest and distribute XMLHttpRequest requests asynchronously. Control is immediately returned to the browser, and the callback function is invoked when the server response arrives.

On the Javaweb server, the incoming request is the same as any other httpservletrequest. After parsing the request parameter, the servlet executes the required application logic, serializes the response into the XML, and writes it back to HttpServletResponse.


An AJAX interaction begins with a JavaScript object called XMLHttpRequest. As the name implies, it allows a client script to execute the HTTP request and will parse an XML-formatted server response. The first step in the AJAX process is to create a XMLHttpRequest instance. Use the HTTP method (get or post) to process the request and set the target URL to the XMLHttpRequest object.

Now, remember how Ajax is first in the asynchronous processing state? When you send an HTTP request, you do not want the browser to hang up and wait for the server to respond, instead, you want to continue to interact with the user's interface through the page and process them after the server response has actually arrived. To do this, you can register a callback function with XMLHttpRequest and distribute XMLHttpRequest requests asynchronously. Control is immediately returned to the browser, and the callback function is invoked when the server response arrives.

On the Javaweb server, the incoming request is the same as any other httpservletrequest. After parsing the request parameter, the servlet executes the required application logic, serializes the response into the XML, and writes it back to HttpServletResponse.


An AJAX interaction begins with a JavaScript object called XMLHttpRequest. As the name implies, it allows a client script to execute the HTTP request and will parse an XML-formatted server response. The first step in the AJAX process is to create a XMLHttpRequest instance. Use the HTTP method (get or post) to process the request and set the target URL to the XMLHttpRequest object.

Now, remember how Ajax is first in the asynchronous processing state? When you send an HTTP request, you do not want the browser to hang up and wait for the server to respond, instead, you want to continue to interact with the user's interface through the page and process them after the server response has actually arrived. To do this, you can register a callback function with XMLHttpRequest and distribute XMLHttpRequest requests asynchronously. Control is immediately returned to the browser, and the callback function is invoked when the server response arrives.

On the Javaweb server, the request to arrive is the same as any other httpservletrequest. After parsing the request parameter, the servlet executes the required application logic, serializes the response into the XML, and writes it back to HttpServletResponse.

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.