How to Create Cross Browser XmlHttpObject

Waqas Anwar
27 June 2009
3767 Views

You want to create browser independent XmlHttpObject in JavaScript for implementing AJAX based asynchronous request and response behavior.

function GetRequest()
{
   var request = null;

   try
   {
      request = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e)
   {
      try
      {
         request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
         if (typeof XMLHttpRequest != "undefined")
         {
            request = new XMLHttpRequest( );
         }
      }
   }
   return request;
}