Skip to content

Instantly share code, notes, and snippets.

@geetotes
Last active April 8, 2019 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geetotes/08ec8c040f9ca23bcf0548bf278996ae to your computer and use it in GitHub Desktop.
Save geetotes/08ec8c040f9ca23bcf0548bf278996ae to your computer and use it in GitHub Desktop.
Stages of XHR Request
  1. Create new XHRequest Object: var client = new XMLHttpRequest();
  2. Assign handler to onreadystatechange event: client.onreadystatechange = handler;
  3. This handler with normally check for a readyState of 4 and a status of 200
function handler() {
if(this.readyState == 4 && this.status == 200) {
// so far so good
if(this.responseXML != null && this.responseXML.getElementById('test').firstChild.data)
   // success!
 test(this.responseXML.getElementById('test').firstChild.data);
else
 test(null);
} else if (this.readyState == 4 && this.status != 200) {
// fetched the wrong page or network error...
test(null);
}
}
  1. Open URL client.open("GET", "test.xml");
  2. Send the request: client.send();

Source: https://www.w3.org/TR/2007/WD-XMLHttpRequest-20071026/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment