A XMLHttpRequest Request: It looked simple enough, now I just want it to work.
-
I've followed a simple example to load an xml file into a table using 'httprequest'. I know my way around code, but this is my first time coding a webpage in 6 years, a 'quicky temp replacement' for a small business website catalog. I'm a hapless newbie once again. The below code worked fine with a sample xml file I made (one with only two records), but when I exported the full file from a database it only returned one line in the table (the xml files have the exact same structure, only more entries). Also, when using this in Firefox it never stops loading. And eventhough there is a clause to make it work with IE, it doesn't. Any help is appreciated, even if it is a complete alternative way of tackling this ... rather basic thing ... The code:
<html>
<head><script type="text/javascript">
var xmlDoc;
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // Internet Explorer 5/6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","Cat2.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;var x=xmlDoc.getElementsByTagName("FMPDSORESULT");
function display()
{
document.write("<table border='0'>");
var x=xmlDoc.getElementsByTagName("ROW");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write("<a href=");
document.write(x[i].getElementsByTagName("IMG")[0].childNodes[0].nodeValue);
document.write(">");
document.write("<img src=");
document.write(x[i].getElementsByTagName("THUMB")[0].childNodes[0].nodeValue);
document.write("/></a>");
document.write("</td><td>");
document.write(x[i].getElementsByTagName("DESCRNL")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("DESCRFR")[0].childNodes[0].nodeValue);
document.write("</td></tr>");}
document.write("</table>");
}
</script>
</head><body>
<button onClick="display()">VINDICATION</button></body>
</html>The xml file (one entry)
<?xml version="1.0" ?>
<FMPDSORESULT>
<ROW MODID="15" RECORDID="27599">
<DESCRFR></DESCRFR>
<DESCRNL>
Een polychrome art deco vaas van zachte pasta. Onderaan gemerkt.
</DESCRNL>
<DIM>
(11 cm)
</DIM>
<EST>
€ 25/30 -
I've followed a simple example to load an xml file into a table using 'httprequest'. I know my way around code, but this is my first time coding a webpage in 6 years, a 'quicky temp replacement' for a small business website catalog. I'm a hapless newbie once again. The below code worked fine with a sample xml file I made (one with only two records), but when I exported the full file from a database it only returned one line in the table (the xml files have the exact same structure, only more entries). Also, when using this in Firefox it never stops loading. And eventhough there is a clause to make it work with IE, it doesn't. Any help is appreciated, even if it is a complete alternative way of tackling this ... rather basic thing ... The code:
<html>
<head><script type="text/javascript">
var xmlDoc;
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // Internet Explorer 5/6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","Cat2.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;var x=xmlDoc.getElementsByTagName("FMPDSORESULT");
function display()
{
document.write("<table border='0'>");
var x=xmlDoc.getElementsByTagName("ROW");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write("<a href=");
document.write(x[i].getElementsByTagName("IMG")[0].childNodes[0].nodeValue);
document.write(">");
document.write("<img src=");
document.write(x[i].getElementsByTagName("THUMB")[0].childNodes[0].nodeValue);
document.write("/></a>");
document.write("</td><td>");
document.write(x[i].getElementsByTagName("DESCRNL")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("DESCRFR")[0].childNodes[0].nodeValue);
document.write("</td></tr>");}
document.write("</table>");
}
</script>
</head><body>
<button onClick="display()">VINDICATION</button></body>
</html>The xml file (one entry)
<?xml version="1.0" ?>
<FMPDSORESULT>
<ROW MODID="15" RECORDID="27599">
<DESCRFR></DESCRFR>
<DESCRNL>
Een polychrome art deco vaas van zachte pasta. Onderaan gemerkt.
</DESCRNL>
<DIM>
(11 cm)
</DIM>
<EST>
€ 25/30Your problem is the empty DESCRFR node - the line
document.write(x[i].getElementsByTagName("DESCRFR")[0].childNodes[0].nodeValue);
is throwing an exception.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
I've followed a simple example to load an xml file into a table using 'httprequest'. I know my way around code, but this is my first time coding a webpage in 6 years, a 'quicky temp replacement' for a small business website catalog. I'm a hapless newbie once again. The below code worked fine with a sample xml file I made (one with only two records), but when I exported the full file from a database it only returned one line in the table (the xml files have the exact same structure, only more entries). Also, when using this in Firefox it never stops loading. And eventhough there is a clause to make it work with IE, it doesn't. Any help is appreciated, even if it is a complete alternative way of tackling this ... rather basic thing ... The code:
<html>
<head><script type="text/javascript">
var xmlDoc;
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // Internet Explorer 5/6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","Cat2.xml",false);
xhttp.send("");
xmlDoc=xhttp.responseXML;var x=xmlDoc.getElementsByTagName("FMPDSORESULT");
function display()
{
document.write("<table border='0'>");
var x=xmlDoc.getElementsByTagName("ROW");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write("<a href=");
document.write(x[i].getElementsByTagName("IMG")[0].childNodes[0].nodeValue);
document.write(">");
document.write("<img src=");
document.write(x[i].getElementsByTagName("THUMB")[0].childNodes[0].nodeValue);
document.write("/></a>");
document.write("</td><td>");
document.write(x[i].getElementsByTagName("DESCRNL")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("DESCRFR")[0].childNodes[0].nodeValue);
document.write("</td></tr>");}
document.write("</table>");
}
</script>
</head><body>
<button onClick="display()">VINDICATION</button></body>
</html>The xml file (one entry)
<?xml version="1.0" ?>
<FMPDSORESULT>
<ROW MODID="15" RECORDID="27599">
<DESCRFR></DESCRFR>
<DESCRNL>
Een polychrome art deco vaas van zachte pasta. Onderaan gemerkt.
</DESCRNL>
<DIM>
(11 cm)
</DIM>
<EST>
€ 25/30Hi Greth, Try it. <html> <head> <script type="text/javascript"> var xmlDoc; if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); }else // Internet Explorer 5/6 { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET","Cat2.xml",false); xhttp.send(""); xmlDoc=xhttp.responseXML; var x=xmlDoc.getElementsByTagName("FMPDSORESULT"); function display() { if(xhttp.readyState==4 && xhttp.status == 200) { var xmlDoc=xhttp.responseXML; var x=xmlDoc.documentElement.getElementsByTagName("FMPDSORESULT"); try { var _txt="<table border='0'>"; var x=xmlDoc.documentElement.getElementsByTagName("ROW"); for (i=0;i<x.length;i++) { _txt+="<tr><td>"; _txt+="<a href="; try{_txt+=x[i].getElementsByTagName("IMG")[0].childNodes[0].nodeValue;}catch(exp0){}; _txt+=">"; _txt+="<img src="; try{_txt+=x[i].getElementsByTagName("THUMB")[0].childNodes[0].nodeValue;}catch(exp0){}; _txt+="/></a>"; _txt+="</td><td>"; try{_txt+=x[i].getElementsByTagName("DESCRNL")[0].childNodes[0].nodeValue;}catch(exp0){}; _txt+="</td><td>"; try{_txt+=x[i].getElementsByTagName("DESCRFR")[0].childNodes[0].nodeValue;}catch(exp0){}; _txt+="</td></tr>"; }_txt+="</table>"; document.getElementById('_DIV').innerHTML=_txt; }catch(exp){alert(exp.message);} } } </script> </head> <body> <button onclick="display()">VINDICATION</button> <div id="_DIV"></div> </body> </html>