Instantiate or Create an XMLHttpRequest (XHR) object is what we must first do. Instantiating or creating a Javascript object should be as easy as :

xhr = new XMLHttpRequest();

Unfortunately, IE5 and IE6 (Internet Explorer 5 and 6) does not support XMLHttpRequest, you need to instantiate it differently by xhr = new ActiveXObject("Msxml2.XMLHTTP"). Having said that, you may also want to make your code to support some very old browsers that does not support it at all.

The good news is, the default web browser that shipped with Windows 10 by the name of Microsoft Edge supports XMLHttpRequest naturally.

Hence, instantiate XHR becoming a little cumbersome where you have to first test how would your user's browser support it.

var xhr;
if (window.XMLHttpRequest) { //For most of modern web browsers
    xhr = new XMLHttpRequest();
    document.getElementById('div1').innerHTML = '<h4>a magical XMLHttpRequest object has been created!</h4>';
}
else if (window.ActiveXObject) { // for IE5, IE6
    xhr = new ActiveXObject("Msxml2.XMLHTTP");
    document.getElementById('div1').innerHTML = '<h4>a Microsoft XMLHTTP ActiveX control object is created!</h4>';
}
else // for stone age web browsers
    document.getElementById('div1').innerHTML = "<h4>Ajax is not supported by this browser</h4>";