Ajax implementation steps

Source: Internet
Author: User

1. Create an XMLHTTPRequest object

2. Register a listener (Receive data from the server)

During Ajax execution, the server notifies the client of the current communication status. Communication status changes must be triggeredOnreadystatechange event, whichThe event processing function is triggered by the server rather than the user.

The server uses the readystate attribute to indicate changes in the current state of the server.
.Its value is represented by numbers.

0 indicates that initialization is not performed. If you have not called open method 1, it indicates loading. The open method has been called, but the send method has not been called. 2 indicates that the load has been completed. Send has been called. The request has started 3, indicating that the request is being interacted. The server is sending a response 4 to complete the process. Response sent

3. Open the connection to the server


XMLHTTP. Open ("Post", URL, true ); Parameter 1: Request Method get post Parameter 2: Request Path Parameter 3: indicates whether the request needs to be asynchronously transmitted. The default value is true (asynchronous) Note: If the request method is post, you need to set the Content-Type type. XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded "); This method must be placed after the Open Method

4. send data to the serverXMLHTTP. Send (PARAM );

If the request method is get, the send method cannot send data to the server. Even if the data is sent, the server cannot receive the data. This parameter is set to null, in this case, you can use URL to pass the parameter eg: XMLHTTP. Open ("get", ".../testservlet? Timestamp = "+ new date (). gettime () +" & Pam = 18 ", true );

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.