AJAX - Client: XMLHttpRequest Object
AJAX Client Side Step By Step Tutorial - part 6: XMLHttpRequest is the object that enable the JavaScript code to make asynchronous HTTP server request. With this, you can make HTTP requests, receive responses, and update parts of the page completely in the background, without any visual interruptions.
A simple version of the code that we will use for cross browser:
// creates XMLHttpRequest Instance
function createXmlHttpRequestObject(){
// will store XMLHttpRequest object
// at here
var xmlHttp;
// works all exceprt IE6 and older
try
{
// try to create XMLHttpRequest object
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
// assume IE 6 or older
try
{
xmlHttp = new ActiveObject("Microsoft.XMLHttp");
}
catch(e){ }
}
// return object or display error
if (!xmlHttp)
alert("Error creating the XMLHttpRequest Object");
else
return xmlHttp;
}
