Any AJAX request starts with the browser making an XMLHttp request object. Most of the new browsers have a built in XMLHttpRequest object. So, it can be created by just simply writing :-

	var = new XMLHttpRequest();
However, Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:-
	var = new ActiveXObject("Microsoft.XMLHTTP");

So, in order to handle every browser, we check whether the browser supports XMLHttpRequest object or not. We make an ActiveX Object in case if it doesn't support it. The final code for making the request is as follows :-

	function getXMLHTTPRequest() {
try {
req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
return req;

In this way, we first try to make a XMLHttpRequest directly if the browser supports it. If not, we make an ActiveXObject for old browsers. So, prior to making any request we need to call this function to create an object and then proceed as follows :-

	var http = getXMLHTTPRequest();

Once we are done with making the XMLHTTPRequest object , lets see how to use this to make a request.

Member Login

Member Login

Not a Member? Sign Up!

Login to comment

Be the first to comment on this topic


<<< Wanna review

Continue >>>