Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. A XMLHttpRequest Request: It looked simple enough, now I just want it to work.

A XMLHttpRequest Request: It looked simple enough, now I just want it to work.

Scheduled Pinned Locked Moved XML / XSL
javascripthtmldatabasebusinesstools
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Greth
    wrote on last edited by
    #1

    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

    S V 2 Replies Last reply
    0
    • G Greth

      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

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Your 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

      1 Reply Last reply
      0
      • G Greth

        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

        V Offline
        V Offline
        Vindhyachal_Kumar
        wrote on last edited by
        #3

        Hi 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>

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups