The basis of all AJAX applications is the aforementioned XMLHttpRequest object. All AJAX-enabled browsers support it natively, but in Internet Explorer the ActiveX object is required. There is one exception, though: Internet Explorer 7 comes with native XMLHttpRequest support. The best approach to create the object is to use TRy…catch and to instantiate the native object first (to get Internet Explorer 7 on the right track even though this browser still supports ActiveX), and then the ActiveX version: if (window.XMLHttpRequest) { // instantiate native object } else if (window.ActiveXObject) { // instantiate ActiveX object } Regarding the ActiveX object, there are several opportunities to instantiate it. The reason: Microsoft ships various versions of their XML library where this object is hidden. A bulletproof solution would be to check for all versions, using a convoluted piece of code. However, the following approach checks only the most important versions and works on Internet Explorer 5 onward and on all other AJAX-aware browsers: Creating the XMLHttpRequest Object (xmlhttp.js)
|