Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Voices That Matter

How To Use AJAX

  • Print
  • + Share This
Like this article? We recommend

Creating the Request Object

To create the request object, you must check whether the browser uses the XMLHttpRequest or the ActiveXObject. The primary difference between the objects is the browsers that use them. Windows IE 5 and above use the ActiveX object; Mozilla, Netscape 7, Opera, and Safari 1.2 and above use the XMLHttpRequest object. Another difference is the way in which you create the objects: Opera, Mozilla, Netscape, and Safari allow you to simply call the objects' constructor, but Windows IE requires the name of the object to be passed to the ActiveX constructor. Following is an example of how to write the code to determine which object to use and how to create it:

if(window.XMLHttpRequest)
{
 request = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
 request = new ActiveXObject("MSXML2.XMLHTTP");
}
  • + Share This
  • 🔖 Save To Your Account