Ajax Knowledge summarization __ajax

Source: Internet
Author: User

1. Get Data using XMLHttpRequest: Open () and send () open (Method,url,anync)
Method:get/post. URL: Address Anync: Submit method, True indicates asynchronous/false represents synchronous Send (String)
If the submission is get,string=null if the submission is post,string= information that needs to be sent

Add
//Set HTTP header information, must be placed between open and send.

Request.setrequestheader (");

//
//

2.XMLHttpREquset Get a response

ResponseText gets the response data returned as a string
Responsexml Gets the response data returned in the form of XML
Stastus and StatusText Returns an HTTP status code as a number and text
Getallresponseheader Get all response headers
getResponseHeader The value of a field in a query response

Readystatus Property

The
4request is complete and the response is ready
0 The request has not been initialized and open has not yet been invoked
1 The server has established a link and open has been called
2 Request received, receive header information
3 In request processing, a response principal is received

Sample

Sends a request and processes--js--
//commits with a GET method, executes the asynchronous commit to the server.php
function () {
    var request=new xmlhttprequest ();
    Request.open ("Get", "server.php", true);
    Request.send ();
    Verify
    request.onreadystatechange=function () {
        if (request.readystatus===4&) by Onreadystatuschange event &request.status===200)
        {
            //If the request succeeds, this part of the Operation
        }else{
            alert ("Error occurred" +request.readystatus);
        }
    }
}
//Add, modify--js--//Submit with Post, execute asynchronous commit to server.php function () {var request=new xmlhttprequest ();
    Request.open ("POST", "server.php", true); Suppose you get data from the form var data= "name=" +document.getelementbyid (' name '). Value + "&age=" +document.getelementbyid (' age '). V
    Alue;
    Set HTTP header information Request.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
    Post mode submission information request.send (data); Verify Request.onreadystatechange=function () {if (request.readystatus===4&&request) by Onreadystatuschange event
        . status===200) {//If the request succeeds, this part of the Operation}else{alert ("Error occurred" +request.readystatus); }
    }
}
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.