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)