How to Create an Instance of the XMLHttpRequest Object - AJAX

XMLHttpRequest is backbone of AJAX framework. We have to first create an XMLHttpRequest object using JavaScript before we can use the object to send request. You can use JavaScript in a couple of ways to create an instance of XMLHttpRequest. Internet Explorer implements XMLHttpRequest as an ActiveX object, and other browsers such as Firefox, Safari, and Opera implement it as a native JavaScript object. Because of these differences, the JavaScript code must contain logic to create an instance of XMLHttpRequest using the ActiveX technique or using the native JavaScript object technique.
var xmlHttp;
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();