Well OK so it mostly works, in IE that is. FF is throwing an error, and it seems to be a fairly common error. I just haven't been able to understand the solutions that I've seen.
I'm getting this in FF:
Code:
theRoot.getElementsByTagName("reviewyear")[i] is undefined
The other posts I've read seem to indicate that this problem occurs if you don't use XMLHttpRequest(), but I am, so I'm lost on this.
Can anyone help?
Here's the js I'm using:
Code:
function showReviews() {
var ajaxGet;
try {
ajaxGet = new XMLHttpRequest();
ajaxGet.open("GET", "reviewtest.xml", true);
ajaxGet.setRequestHeader("Content-Type", "text/xml");
}
catch (err) {
ajaxGet = new ActiveXObject("Microsoft.XMLHTTP");
ajaxGet.open("GET", "reviewtest.xml", true);
ajaxGet.setRequestHeader("Content-Type", "text/xml");
}
ajaxGet.onreadystatechange = function() {
if (ajaxGet.readyState == 4) {
var theResponse = ajaxGet.responseXML;
var theRoot = theResponse.documentElement; // get the root element
var tempYears = new Array;
for(i = 0; i < theRoot.childNodes.length; i++){
//// the problem is here: "theRoot.getElementsByTagName("reviewyear")[i] is undefined"
tempYears[i] = theRoot.getElementsByTagName("reviewyear")[i].childNodes[0].nodeValue;
}
}
}
ajaxGet.send(null);
}
and here's the xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<archive>
<review>
<review_id>1</review_id>
<filmtitle>Test</filmtitle>
<director>Director 1</director>
<producer>Producer 1</producer>
<filmyear>2001</filmyear>
<reviewtitle>Review Title 1</reviewtitle>
<caption>Review Caption 1</caption>
<reviewday>15</reviewday>
<reviewmonth>1</reviewmonth>
<reviewyear>2009</reviewyear>
</review>
<review>
<review_id>2</review_id>
<filmtitle>Test 2</filmtitle>
<director>Director 2</director>
<producer>Producer 2</producer>
<filmyear>2002</filmyear>
<reviewtitle>Review Title 2</reviewtitle>
<caption>Review Caption 2</caption>
<reviewday>16</reviewday>
<reviewmonth>2</reviewmonth>
<reviewyear>2009</reviewyear>
</review>
</archive>
Bookmarks