I am calling a javascript from a button using onclick(). The javascript will go through the xml file and list the text in the child nodes under username. When running the code the page posts back to the top but nothing happens.
xml:
<?xml version="1.0" encoding="utf-8"?>
<users>
<user>
<username>chuckbeyor101</username>
<playlist>
<song>
<ink>http://ift.tt/1m8dAu0;
</song>
</playlist>
</user>
</users>
html:
<a href="#" onclick="return myFunction();" ><img src="/images/playlist.png" alt="Add to Playlist" ></a>
<script>
function myFunction() {
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","users.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
x=xmlDoc.getElementsByTagName("users");
i=0;
function displayCD()
{
username=(x[i].getElementsByTagName("username")[0].childNodes[0].nodeValue);
alert(username);
}
}
</script>
No comments:
Post a Comment