The following code does not work, it took a lot of time to find errors, and finally found a sign in the for loop wrong.
Write it down and give yourself a warning: for (i=0;i<x.length;i++), here i=0 and i<length should be separated by semicolons!
<script>
function Loadxmldoc ()
{
var xmlhttp;
var txt,x,i;
if (window. XMLHttpRequest)
{//code for ie7+, Firefox, Chrome, Opera, Safari
Xmlhttp=new XMLHttpRequest ();
}
Else
{//code for IE6, IE5
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
}
Xmlhttp.onreadystatechange=function ()
{
if (xmlhttp.readystate==4 && xmlhttp.status==200)
{
Xmldoc=xmlhttp.responsexml;
Txt= "";
X=xmldoc.getelementsbytagname ("ARTIST");
for (i=0,i<x.length;i++)
{
Txt=txt + x[i].childnodes[0].nodevalue + "<br>";
}
document.getElementById ("Mydiv"). Innerhtml=txt;
}
}
Xmlhttp.open ("GET", "Cd_catalog.xml", true);
Xmlhttp.send ();
}
</script>
<body>
<div id= "Mydiv" ></div>
<button type= "button" onclick= "Loadxmldoc ()" >get my CD collection</button>
</body>
Once made a mistake: whether to use a semicolon or a comma