< Prev :Contents: Next >

Example

For this example, please note the function getXmlHttp has been already defined as: 

function getXmlHttp()
{
try
{
// Return an XMLHttpRequest object for most browsers
return new XMLHttpRequest();
}
catch(exception)
{
try{
// For newer IE browsers
return new ActiveXObject("Msxml2.XMLHTTP");
}
catch(exception)
{
try{
//For older IE browsers
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch(exception)
{
//Could not create XMLHttp object
return null;
}
}
}
}

Here is an example that retrieves an xml file. Note that we are not checking for the status so that this example will work even from the local file system. Click run to run the example. You can change the script and experiment with it.  What happens here is it loads the file abc.xml and sets the div in output with the data that is in the file. There is also a file called 123.xml and xyz.xml to experiment with. Note that since they are just files and not server scripts, there is no point sending request variables. Otherwise, request data could also be sent.

Output:
 

If there was data to be sent in the request, it would have been appended to the URL after a '?', so the URL would look like: "abc.php?param1=value1&param2=value2&param3=value3".

Creative Commons License This work is licenced under a Creative Commons Licence. More details in the content page.

< Prev :Contents: Next >