Home / Articles / How To Use AJAX

How To Use AJAX

Article Description

AJAX, an acronym for Asynchronous JavaScript and XML, is very hot in the growing universe of Web development. While this new technology offers some great capabilities, it also sparks some unquestionable debate over issues with the Back button. Kris Hadlock explains how to use AJAX in a real-world situation and how you can assess its value in a project. By the time you finish reading this article, you'll know what AJAX is as well as where, why, and how to use it.

Like this article? We recommend

Adobe Photoshop CS2 Official JavaScript Reference

Adobe Photoshop CS2 Official JavaScript Reference

$39.99

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");
}
5. Making the Request | Next Section Previous Section