Ajax XMLHttpRequest : Creating Request Object



Previously we have learnt about different blocks in the Ajax example. This tutorial explains more about the creation of the XMLHttpRequest request object in the Ajax.

Ajax XMLHttpRequest Request :

var xmlhttp;

if (window.XMLHttpRequest) { 
   // code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp = new XMLHttpRequest();
} else { 
   // code for IE6, IE5
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

Recommanded Reading : Click here to see complete example

XMLHttpRequest Object :

  1. XMLHttpRequest object is supported in all modern browsers however IE5 and IE6 uses an ActiveXObject.
  2. Object is used to exchange data with a server without reloading the whole page.
  3. Updating part of web page is possible using XMLHttpRequest object
  4. For creating an XMLHttpRequest object in Chrome,opera,safari and Firefox, syntax is shown below –
  5. variable = new XMLHttpRequest();
    
  6. Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:
  7. variable = new ActiveXObject("Microsoft.XMLHTTP");