Error by reading a xml file
Hello!
I've written a code, that should be reading xml with js. But I have make an error. Can you help me?
HTML Code:
<html>
<head>
<title> Test</title>
<script type="text/javascript" > <!--
var http = null;
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
window.onload = function() {
if (http != null) {
http.open("GET", "http://www.eucharistiefeier.de/lk/api/lkul00000000.xml", true);
http.onreadystatechange = ausgeben;
http.send(null);
}
}
function ausgeben() {
if (http.readyState == 4) {
var bible = document.getElementById("bible");
var daten = http.responseXML;
var ergebnisse = daten.getElementsByTagName("celebration");
for (var i = 0; i < ergebnisse.length; i++) {
var name, url;
var datum = ergebnisse[i];
for (var j = 0; j < datum.childNodes.length; j++) {
with (datum.childNodes[j]) {
if (nodeName == "l1") {
name = firstChild.nodeValue;
} else if (nodeName == "ev") {
url = firstChild.nodeValue;
}
}
}
var p = document.createElement("p");
var r1 = document.createTextNode("Die heutige Tageslesung ist: " + name);
p.appendChild(r1);
bible.appendChild(p);
}
}
}
//-->
</script>
</head>
<body>
<ul id="bible" > </ul>
</body>
</html>
LG
Luensche
P. S.: Following error message came, when I let run "Firebug"
Uncaught TypeError: Cannot call method 'getElementsByTagName' of null
The error shold be in line 23, perhaps the problem is var http = null;
this is kind of a guess, but shouldn't that line be:
Code:
var ergebnisse = daten.documentElement.getElementsByTagName("celebration");
?
Code:
http.open("GET", "http://www .eucharistiefeier.de/lk/api/lkul00000000.xml", true);
AJAX can not, alone, make request cross domains. Even if that is your domain, the fact that the address is written as absolute will make some servers (like Apache) to consider it as a cross-domain request and will block it.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks