The XMLHTTPRequest Object
We need to substantiate an XMLHTTPRequest object in order to use Ajax on our page. Here\'s the code for a function to do so:
function getXMLHTTPObject() {
try {
req = new XMLHttpRequest();
} catch(err1) {
try {
req = new ActiveXObject(\"Msxml2.XMLHTTP\");
} catch (err2) {
try {
req = new ActiveXObject(\"Microsoft.XMLHTTP\");
} catch (err3) {
req = false;
}
}
}
return req;
}Note that the above code makes several attempts to instantiate the object using a number of function calls. We need to do this because various browsers have different methods of handling the XMLHTTPRequest object.
We can now instantiate the object, irrespective of which browser is being used, by using the following line of code:
var http = getXMLHTTPObject();
This site is brand new and so still somewhat under construction.
Why not bookmark it and call back regularly?