This is the second part of my four-part series, Active Client Pages – Ajax Approach. In this part of the series, we continue our discussion of the Ajax features we will need to use with ACP, and then we look at the principles of the Ajax approach.
XMLHttpRequest Object
By using the XMLHttpRequest object, a web developer can update a page with data from the server after the page has loaded! The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, Opera 8+, and Netscape 7.
Ajax Browsers
The keystone of AJAX is the XMLHttpRequest object. Different browsers use different methods to create the XMLHttpRequest object. Internet Explorer uses an ActiveXObject, while other browsers uses the built-in JavaScript object called XMLHttpRequest.
All Ajax requests in JavaScript begin by making a call to the XMLHttpRequest constructor function:
- new XMLHttpRequest() //IE7, Firefox, Safari etc;
- new ActiveXObject(“Msxml2.XMLHTTP”) //newer versions of IE5+;
- new ActiveXObject(“Microsoft.XMLHTTP”) //older versions of IE5+;
- new XDomainRequest() //IE8+ only. A more “secure”, versatile alternative to IE7’s XMLHttpRequest() object.
In IE6 and below, the XMLHttpRequest() is not supported, but instead relies on the proprietary ActiveXObject for Ajax requests. To create this object, and deal with different browsers, we are going to use a “try and catch” statement. Continue reading