XMLHttpRequest Basic Knowledge

Source: Internet
Author: User

XMLHttpRequest two important ways to send requests:
Open (Method,url,async)--Parameters: Request mode, request address, request synchronous/asynchronous;
Send (String)--parameter: Fill in this parameter when using post mode.

Usage examples:
Request.open ("POST", "create.php", true);
Request.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); To write between open and send
Request.send ("Name= Zhang San &sex= male");

XMLHttpRequest gets several important properties and methods of the response:
Reponsetext: Getting response data in string form
Reponsexml: Getting response data in XML form
Status and StatusText: Returns the HTTP status code in numeric and textual form
Getallreponseheader (): Gets all the response headers
getResponseHeader (): Gets the value of a field in the response
The change in the ReadyState property represents a change in the server response:
0: Request uninitialized, Open has not been called
1: The server connection has been established and open has been called
2: The request has been received, that is to receive the header information
3: The request is processed, that is, the response body is received
4: The request is complete and the response is ready, that is, the response is complete

Tips:
Use the onReadyStateChange event to listen for HTTP request processing,
When Readystate===4 && status===200 indicates that the response is complete and the request is successful,
So that we can use the data obtained from the background to do the corresponding operation.

XMLHttpRequest Basic Knowledge

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.