function makeRequest(url) {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
}
}
}
if (xhr) {
xhr.addEventListener("readystatechange",showContents,false);
xhr.open("GET", url, true);
xhr.send(null);
}
else {
document.getElementById("updateArea").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
}
}
3 Parts:
1) Create xhr (XmlHttpRequest)
2) Evaluate xhr
3) Output xhr's data (outMsg)
Here we are using the onreadystatechange event From XMLHttpRequest Object Events list
You guessed it, Microsoft. This Section in the brown is asking “did the user make the unfortunate choice of using a Microsoft Browser”, if so set xhr as a MS XMLHttp Object
Make xhr a XMLHttpRequest Object for all browsers except...
An Http Request Method: GET, POST or HEAD
Asynchronous: True or Syncronous:False
Open and Send the HTTP Request
Handle No xhr object scenario with error message