Java Web Basics: 20th Ajax Overview __ Database

Source: Internet
Author: User

This article is excerpted from: The Java Web development tutorial-Getting Started and improving (Jsp+servlet) AJAX is an acronym for Asynchronous JavaScript and XML, involving JavaScript scripts, XHTML and CSS, DOM, XM L and Xstl technology. l         XHTML and CSS to achieve unified and standardized display of data information; l          use DOM to implement rich dynamic display and interaction with the server on the browser side; l         using XML and Xstl The browser and server-side data exchange and processing, l         using XMLHttpRequest object for browser and server-side asynchronous data reading; l          use JavaScript scripting to implement further processing of all data. The core working process of AJAX is as follows: 1.         object initialization, primarily to create XMLHttpRequest objects, XMLHttpRequest Object is a very core object in Ajax technology, which is responsible for the setting and sending of the request. 2.         sends the request, sets the response method, the data required for the request, and then sends the request. The 3.         server receives the request and processes it, typically by the servlet receiving the request, then invoking the appropriate business method to process it and then responding to the user. 4.         the client responds, receives a response and then invokes the response method previously set. 5.         The response method modifies the client page content based on the response data. With Ajax technology, the interaction between the client and the server has been changed. Before Ajax technology is used, the user submits the request by setting the action attribute of the <form> form, submitting the requests via the Submit button, or submitting the form's Submit method in JavaScript code. AJAX is essentially adding JavaScript technology and XMLHttpRequest objects between Web Forms and servers. When a user fills out a form, the data is sent to some JavaScript code and then sent through the XMLHttpRequest object instead of being sent directly to the server. In this process, the form on the user's screen does not blink, disappear, or delay. JavaScript code sends a request behind the scenes, and the user doesn't even know the request is sent. Better yet, requests are sent asynchronously, meaning that JavaScript code (and users) does not have to wait for a response from the server. So users can continue to enter data, scroll the screen, and use the application. The server then returns the data and invokes the received method defined at the request, which processes the data, updates the form data, makes the impression that the application is executed locally, that the form is not submitted, and that the page is only partially refreshed. The response code can also perform some sort of calculation on the received data, or send the request again. The processing code mainly uses the JavaScript technology, but the interaction with the server is done mainly through the XMLHttpRequest object. The properties and functions of the XMLHttpRequest object are shown in Table 4.2. Table 4.2  xmlhttprequest Properties

Property Role
onReadyStateChange Event triggers for state changes
ReadyState Object state 0 means uninitialized 1 means read 2 indicates read 3 indicates that 4 of the interaction is complete
ResponseText The text of the server process returning data, represented as a string
Responsexml The XML Document object that the server process returns the data as a compatible DOM
Status The status code returned by the server, such as: 404 (File not found). 200 (success).
StatusText Status text information returned by the server (OK or not Found, etc.)
The main methods and functions of XMLHttpRequest objects are shown in Table 4.3. Table 4.3 Methods for XMLHttpRequest objects

Method Function
Abort () Stop current request
getAllResponseHeaders () Returns all the response headers of an HTTP request as a key/value pair
getResponseHeader ("Headerlabel") Returns the value of the string for the specified header
Open ("Method", "URL" "[, asyncflag[," username "[," Password "]]] Connect access to the server. Where the method parameter can use GET, POST, and put, the URL parameter can either use an absolute address or a relative address, and the Asyncflag parameter is used to specify whether the call is synchronous or asynchronous, and the default value is true, that is, asynchronous. If the parameter value is false, the interaction with the server is implemented synchronously, waiting for the server to return the response, username specify the user name at the time of the connection, password indicate the password.
Send (content) Requests are sent to the server, and parameters that can be used include DOM objects, strings, and so on.
setRequestHeader ("label", "value") Sets the header and sends it along with the request, specifying that the header is set to the supplied value, and that the open () method must be used before the header is set. The name of the first parameter, the value in the head of the second parameter.

  Last: 19th speaking JavaScript processing (ii) Next: 21st on the basic process of Ajax interaction Li Shengcheng CSDN blog:http:// Blog.csdn.net/javaeeteacher invite you to be a friend: Http://student.csdn.net/invite.php?u=124362&c=7be8ba2b6f3b6cc5

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.