XMLHttpRequest Object in AJAX:

XMLHttpRequest object also known as XHR and it is an Application Program Interface(API) and used by all web browser scripting languages like JavaScript, Jscript, VBScript languages to manipulate and transfer data from and to the web server using HTTP.

Basically this XHR is used behind the scene to exchange data with a server. So this means this object is responsible for updating parts of a web page without refreshing whole page.

Method of creating XMLHttpRequest Object:

To create a XMLHttpRequest object you have to know that all new browser inherent or built-in XMLHttpRequest object. But for the older versions of Internet Explorer like IE5 and IE6 you have to use ActiveX Object.

Below is syntax for both Methods:

Syntax:

How to create XMLHttpRequest Object?

variable_name = new XMLHttpRequest();

Syntax:

How to create ActiveX Object?

variable_name=new ActiveXObject(“Microsoft.XMLHTTP”);

So now you understand that if you are using modern browser than you need to create XMLHttpRequest object and if you are using older than you have to create ActiveX object.

Example:

//Creating a new XMLHttpRequest object

var xmlhttp;

if (window.XMLHttpRequest)

{

xmlhttp = new XMLHttpRequest(); //for IE7+, Firefox, Chrome, Opera, Safari

}

else

{

xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”); //for IE6, IE5

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *