Configure HTML/JavaScript

Sunday, May 23, 2010

JavaScript ajax call using xmlHttpRequest and xmlHttpResponse

var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() {
  var xmlHttp;
// if running Internet Explorer  if(window.ActiveXObject) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlHttp = false;
      }
    }
  } else { // if running Mozilla or other browsers    
    if(!xmlHttp && typeof ActiveXObject == "undefined") {
      try {
        xmlHttp = new XMLHttpRequest();
      } catch (e) {
        xmlHttp = false;
      }
    }
  }
// return the created object or display an error message  if (!xmlHttp) {
    alert("Error creating the XMLHttpRequest object.");
  } else {
    return xmlHttp;
  }
}


No comments:

Post a Comment