For some reason, I keep getting XMLDoc is null, in firebug. I think that perhaps my program isn’t parsing the XML that I am trying to generate (and that means I am likely not doing it correctly).
NOTE: I DO NOT WANT TO USE JQUERY HERE!
Here’s my code that is supposed to generate the XML code:
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("generic");
$rescult = mysql_query("SELECT * FROM culture order by cult_id");
if (!$rescult) {
die('Invalid query: ' . mysql());
}
$row = mysql_fetch_row($rescult);
ECHO "<item>";
ECHO "<item1>" . $row[0] . "</item1>" . "<br />";
ECHO "<item2>" . $row[1] . "</item2>" . "<br />";
ECHO "</item>";
?>
And here’s my code that is supposed to parse it:
<html>
<header>
<script type="text/javascript">
if (window.XMLHttpRequest)
{ // Code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{
// Code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","testitout2.php",false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
document.getElementById("item1").value =
xmlDoc.getElementsByTagName("item1")[0].childNodes[0].nodeValue;
document.getElementById("item2").value =
xmlDoc.getElementsByTagName("item2")[0].childNodes[0].nodeValue;
</script>
</header>
<body>
<input type="text" id="item1">
<input type="text" id="item2">
</body>
</html>
Edit: I didn’t notice the
asyncflag. Guess my answer is irrelevant then.You are trying to access XML before it was even loaded.
Set property
onreadystatechangetoxmlhttp: