JS Ajax Request Flow

Source: Internet
Author: User

<input type= "button" Name= "btn" id= "btn" value= "button"/>

Js

Click the button to eject the 1.txt content
var Obtn=document.getelementbyid ("btn"); Obtn.onclick=function () {//Open Browser/* 1. Create an Ajax object IE6 the following new ActiveXObject (' Microsoft.XMLHTTP ') * */var xhr=null;try{xhr=new XMLHttpRequest ();} catch (e) {xhr=new activexobject (' Microsoft.XMLHTTP ');} In the Address bar, enter the address/*open method parameter 1. Open with 2. Address 3. Asynchronous Async: The code in front of nonblocking mode does not affect the execution synchronization of subsequent code: the code in front of blocking mode affects the execution of subsequent code * */
Asynchronous request Xhr.open (' Get ', ' 1.txt ', true);//Submit Send request Xhr.send ();//wait for the server to return content/*readystate:ajax work status request status * 0 (Initialize) No call to open () method * 1 (load) already called the Send () method, sending request * 2 (loading complete) the Send () method completed, received full response content * 3 (resolution) is parsing the response content * 4 (completion) Response content resolution completed, can be called on the client * STA Tus property: The state of the server (request Resource), the content returned by the HTTP status code responsetext: Returns content stored as text responsexml: Returns the content in XML form */xhr.onreadystatechange= function () {if (xhr.readystate==4) {if (xhr.status==200) {alert (xhr.responsetext);} Else{alert (' Error, ERR ' +xhr.status);}}}

  

 

JS Ajax Request Flow

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.