Ajax methods Xhr.readystate five states and examples

Source: Internet
Author: User

Methods Xhr.readystate of five states


Xhr.readystate = = Status (0,1,2,3,4) 0: The request was not initialized and open () was not called. 1: The request has been established, but has not been sent yet, and the Send () has not been called. 2: The request has been sent, is in process (usually can now get the content header from the response). 3: The request is in process, and some of the data in the response is usually available, not all completed.   4: The response is complete; you can get and use the server's response. Methods Xhr.status Common states Xhr.status = = 200,300,404 100--customers must continue to make requests 101--customer requests that the server convert the HTTP protocol version on request
200--successful 201--prompt to know the URL of the new file
300--requested resource can get 301--delete request data in multiple places
404--no file, query, or URL 500--server generated an internal error index.php
o T X
for.php
For (Echo
"; Sleep (1);
var xmlHttp; function S_xmlhttprequest () {if (window. ActiveXObject) {xmlHttp = new ActiveXObject (' Microsoft.XMLHTTP ');} else if (window. XMLHttpRequest) {xmlHttp = new XMLHttpRequest ();}}
function funphp100 (URL) {s_xmlhttprequest (); Xmlhttp.open ("GET", "for.php?id=" +url,true); Xmlhttp.onreadystatechange = byphp; Xmlhttp.send (NULL); }
function byphp () {
if (xmlhttp.readystate = = 1) {document.getelementbyidx_x (' php100 '). InnerHTML = "Loading ....";}
if (xmlhttp.readystate = = 4) {if (Xmlhttp.status = =) {var byphp100 = Xmlhttp.responsetext; document.getelementbyidx_x ( ' php100 '). InnerHTML = byphp100; } }
}

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.