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 );