I have a xml file named devoir.xml
My code is
<!DOCTYPE html>
<html>
<style>
table,th,td {
border : 1px solid black;
border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>
<button type="button" value="button text" onclick="loadXMLDoc()";>Avoir les nouvelles.</button>
<table id="demo"></table>
<script language="javascript">
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 and xmlhttp.status == 200) {
myFunction(xmlhttp);
}
};
xmlhttp.open("GET", "devoir.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var table="<tr><th>Titre</th><th>Description</th></tr>";
var x = xmlDoc.getElementsByTagName("item");
for ( var i = 0 ; i < x.length ; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
</script>
</body>
</html>
The page load but when i push on the button there is nothing happening at all. Any idea what's going on?
I have try to change somestuff into my code but always the same result. I have try another thing online and it's not working also. Any idea?