i am writing an ajax code to collect information from a xml file but the file is not being read can someone please point out the problem for me the code is below.
<html>
<head>
<title></title>
<script type="text/javascript">
var xmlHttpDoc = new XMLHttpRequest();
/*getcolor1 function*/
var options;
function getColor1()
{
if(xmlHttpDoc)
{
xmlHttpDoc.open("GET", "options1.php", true);
xmlHttpDoc.onreadystatechange = function()
{
if(xmlHttpDoc.readyState==4 && xmlHttpDoc.status==200)
{
var xmlDocument = xmlHttpDoc.responseXML;
/*the line below is returning null*/
options = xmlDocument.getElementsByTagName('option');
listOptions();
}
}
xmlHttpDoc.send(null);
}
}
/*getcolor2 function*/
function getColor2()
{
if(xmlHttpDoc)
{
xmlHttpDoc.open("GET", "options2.php", true);
xmlHttpDoc.onreadystatechange = function()
{
if(xmlHttpDoc.status==200 && xmlHttpDoc.readyState==4)
{
}
}
xmlHttpDoc.send(null);
}
}
/*setoption function*/
function setoption()
{
if(xmlHttpDoc)
{
xmlHttpDoc.open("GET", datasource, true);
xmlHttpDoc.onreadystatechange = function()
{
if(xmlHttpDoc.status==200 && xmlHttpDoc.readyState==4)
{
}
}
xmlHttpDoc.send(null);
}
}
/*dont understand yet*/
function listOptions()
{
var loopIndex;
for (loopIndex = 0; loopIndex < options.length; loopIndex++ )
{
var selectControl = document.getElementById('optionList');
for (loopIndex = 0; loopIndex < options.length; loopIndex++ )
{
selectControl.options[loopIndex] = new Option(options[loopIndex].firstChild.data);
}
}
}
</script>
</head>
<body>
<form>
<select size="1" id="optionList" onchange="setOption()">
<option>Select a scheme</option>
</select>
<span><input type="button" value="Color 1" onclick = "getColor1()"/></span>
<span><input type="button" value="Color 2" onclick = "getColor2()"/></span>
</form>
<div id="targetDiv" width =100 height=100>Color this text.</div>
</body>
</html>