Hi
I have just started learning AJAX. I have found an example and this is the contents of the .js file:
Code:
 
function loadData(URL)
{
// Create the XML request 
xmlReq = null;
if(window.XMLHttpRequest) xmlReq = new XMLHttpRequest();
else if(window.ActiveXObject) xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
 
if(xmlReq==null) return; // Failed to create the request
 
// Anonymous function to handle changed request states
 
xmlReq.onreadystatechange = function()
 
{
switch(xmlReq.readyState)
{
case 0: // Uninitialized
break;
case 1: document.getElementById("image").src = "up.png"; // Loading
break;
case 2: // Loaded
break;
case 3: // Interactive
break;
case 4: // Done!
// Retrieve the data between the <quote> tags
 
doSomethingWithData(xmlReq.responseXML.getElementsByTagName('quote')[0].firstChild.data);
 
break;
 
default:
 
break;
 
}
 
}
 
// Make the request
 
xmlReq.open ('GET', URL, true);
 
xmlReq.send (null);
}
And then there is the data.xml file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<root>
	<quote>Silence is foolish if we are wise, but wise if we are foolish (Charles Colton)</quote>
</root>
And on the html page is:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="ajax.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="ajax.js"></script>
<script language = "JavaScript">
<!--
// Function to call with the data retrieved from the XML file 
function doSomethingWithData(datastr)
{
	document.getElementById('MyID').innerHTML = datastr;
}
//-->
</script>
<title>AJAX Tutorial: Example 2</title>
</head>
<body>
<p>
<img border="0" id = "image" src="down.png" width="15" height="15"><br>
<br>
<input type="button" value="Load data.xml" onclick="loadData('data.xml');" />
</p>
<p>
<div id="MyID">&nbsp;</div>
</body>
</html>
I have played around with this a bit and have got it to work and I understand sort of how it works. Now how is it possible to put information from a database into the xml file and then display a html table of that information?

Thanks very much in advance,
Ben Sheard