How to Create Cross Browser XmlHttpObject


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;
}

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments