+91 90691 39140 | +1 253 214 3115 | info@hub4tech.com | hub4tech

AJAX XMLHttpRequest Object


  • The XMLHttpRequest object is the key to AJAX.
  • XMLHttpRequest (XHR) is an API that can be used by JavaScript, JScript, VBScript, and other web browser scripting languages to transfer and manipulate XML data to and from a webserver using HTTP, establishing an independent connection channel between a webpage's Client-Side and Server-Side.
  • The data returned from XMLHttpRequest calls will often be provided by back-end databases. Besides XML, XMLHttpRequest can be used to fetch data in other formats, e.g. JSON or even plain text.

Creating an XMLHttpRequest Object

All modern browsers (Chrome, IE7+, Firefox, Safari, and Opera) have a built-in XMLHttpRequest object. So in order to begin using AJAX the first and foremost step is the creation of XMLHttpRequest Object with the help of which all the actions are performed. The object is created using java script. Since Ajax is a web browser dependent technology, so creation of XMLHttpRequest (XHR) object also varies from browser to browser. The most common way of creating this object is as shown below:

Syntax for creating an XMLHttpRequest object

For Old versions of Internet Explorer (IE5 and IE6) use an ActiveX Object:
varobj=newActiveXObject("Microsoft.XMLHTTP");

For other types of browsers (Chrome, IE7+, Firefox, Safari, and Opera)
var obj =newXMLHttpRequest ();

To handle all browsers, including IE5 and IE6, check if the browser supports the XMLHttpRequest object. If it does, create an XMLHttpRequest object, if not, create an ActiveXObject.

Sample Code for creating object (Chrome, IE7+, Firefox, Safari, and Opera)

AJAX XMLHttpRequest Object

Sample Code for creating object (IE5 and IE6)

AJAX XMLHttpRequest Object


Is it Helpful?
Copyright ©2015 Hub4Tech.com, All Rights Reserved. Hub4Tech™ is registered trademark of Hub4tech Portal Services Pvt. Ltd.
All trademarks and logos appearing on this website are the property of their respective owners.
FOLLOW US