Okay i cannot solve this problem for 2 days straight.. This examlpe here: http://ift.tt/1x3d0oK works just fine on the w3schools site. But when i copy and paste the code in notepad++. It doesn't work. I have the XML file downloaded. Than i was reading that AJAX doesn't support work with local files. I don't get this?? I have an assingment for school to work with a local XML file. How can i work with local XML file and AJAX when AJAX doesn't support working with local files. And the only response that i get from the teaching assistant is that i should use firefox... But No.. it doesn't work on : Chrome, Internet Explorer, Mozila, Opera.. basicaly nothing...
I know that something similar has been asked here but i just can't make it work. If anyone got any idea how can i modify this given code to work localy, i would be thankful.. THANKS in advance..
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(url) {
var xmlhttp;
var txt, x, xx, 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) {
txt = "<table border='1'><tr><th>Title</th><th>Artist</th></tr>";
x = xmlhttp.responseXML.documentElement.getElementsByTagName("CD");
for (i = 0; i < x.length; i++) {
txt = txt + "<tr>";
xx = x[i].getElementsByTagName("TITLE"); {
try {
txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
} catch (er) {
txt = txt + "<td> </td>";
}
}
xx = x[i].getElementsByTagName("ARTIST"); {
try {
txt = txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
} catch (er) {
txt = txt + "<td> </td>";
}
}
txt = txt + "</tr>";
}
txt = txt + "</table>";
document.getElementById('txtCDInfo').innerHTML = txt;
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="txtCDInfo">
<button onclick="loadXMLDoc('cd_catalog.xml')">Get CD info</button>
</div>
</body>
</html>
No comments:
Post a Comment