- Create new XHRequest Object:
var client = new XMLHttpRequest();
- Assign handler to
onreadystatechange
event:client.onreadystatechange = handler;
- This handler with normally check for a
readyState
of 4 and astatus
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);
}
}
- Open URL
client.open("GET", "test.xml");
- Send the request:
client.send();
Source: https://www.w3.org/TR/2007/WD-XMLHttpRequest-20071026/