Cross Browser and Ajax
We all know that the core of the Ajax technique is the
XMLHttpRequest
object available in JavaScript. But this object is not necessarily available in your browser, especially in Internet Explorer, depending upon the browser and platform.It can be instantiated natively in browsers such as Mozilla Firefox, Google Chrome, Safari, and even IE7 or later, which support the native
XMLHttpRequest
object as follows:var xmlHttpObj = new XMLHttpRequest();
Now, in Internet Explorer 6 or 5, to use the
XMLHttpRequest
object, it has be created as a ActiveX object in JavaScript:var xmlHttpObj = new ActiveXObject("MSXML2.XMLHTTP.3.0");
But even the ActiveX object class can be different from one Windows platform to another, so we might also have to use the following code:
var xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
Now, let's create an Ajax function that will return the
XMLHttpRequest
object in a cross-browser platform:function getAjaxObj() { var xmlHttpObj = null; ...