There are many syntax errors in the table string creation code:
Code:
var tableHTML = "<table border='1'>", x = xmlhttp.getElementsByTagName("offers");
for (i = 0; i < x.length; ++i)
{
tableHTML += "<tr><td>";
tableHTML += x([i].getElementsByTagName("programName")[0].childNodes[0].nodeValue);
tableHTML += "</td><td>";
tableHTML += x([i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
tableHTML += "</td><td>";
tableHTML += "<img src='" + x([i].getElementsByTagName("programLogo")[0].childNodes[0].nodeValue) + '" alt=''>";
tableHTML += "</td></tr>";
}
tableHTML += "</table>");
It should be:
Code:
var tableHTML = "<table border='1'>", x = xmlhttp.getElementsByTagName("offers");
for (i = 0; i < x.length; ++i)
{
tableHTML += "<tr><td>";
tableHTML += x[i].getElementsByTagName("programName")[0].childNodes[0].nodeValue;
tableHTML += "</td><td>";
tableHTML += x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue;
tableHTML += "</td><td>";
tableHTML += "<img src='" + x[i].getElementsByTagName("programLogo")[0].childNodes[0].nodeValue + "' alt=''>";
tableHTML += "</td></tr>";
}
tableHTML += "</table>";
If there's still a problem -
Have you tested to determine if you have a valid XML object? Like here:
Code:
xmlhttp.open("GET","url link",false);
xmlhttp.send();
xmlhttp=xmlhttp.responseXML;
alert(xmlhttp);
You should get something like (depending upon the browser):
[object]
XML OBJECT
If you get null or anything that's not an object, there's a problem fetching the content. If you get an object of some sort, the next thing to test is the the assumption that the object you have there has a:
Code:
xmlhttp.getElementsByTagName("offers")
like:
Code:
var tableHTML = "<table border='1'>", x = xmlhttp.getElementsByTagName("offers");
alert(x.length);
That has to be at least 1 or you will have no output. If it's not 1 or more or not a number, there's a problem. Check that there are any tags:
Code:
alert(xmlhttp.getElementsByTagName("*").length);
If all that checks out and there are still problems determine if the child tags you are looking for in the XML object are there - use a similar strategy for each as already outlined.
Two more bits of advice - often you must test things like this live (or on a localhost server that simulates a live web installation), and all files must be on the same domain, otherwise there will be a same origin policy security violation in any modern browser.
If you want more help, please post a link to the page on your site that shows the problem.
Bookmarks