Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts

    httpRequest with XML - Mozilla not seeing data

    I have an asp page that generates phonebook entries as an xml document based on the input of the user. The server side code is not the problem so I cut out all of the code and left the xml.
    Code:
    <% Response.ContentType = "text/xml" %>
    <?xml version="1.0" ?>
      <phonebook>
        <entry>
          <name>Tom Thumb</name>
          <number>(123) 456-7890</number>
        </entry>
        <entry>
          <name>Tom Stubs</name>
          <number>(987) 654-3210</number>
        </entry>
      </phonebook>
    And I have the JavaScript code that is grabbing the xml and formatting the data into the table.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
      <head> 
        <title>Test</title> 
    	<style type="text/css">
    	  table{border: 1px solid black; border-collapse: collapse;}
    	  th, td{border: 1px solid black; padding: 3px;}
    	</style>
        <script type="text/javascript">
    
          var reqXML;
          function GrabNumber(){ 
            url  = 'phone.asp?name=' + document.Form1.user.value;
            LoadXMLDoc(url);
          } 
        
          function LoadXMLDoc(url){ 
            if(window.XMLHttpRequest){ 
              reqXML = new XMLHttpRequest(); 
              reqXML.onreadystatechange = BuildXMLResults; 
              reqXML.open("GET", url, true); 
              reqXML.send(null); 
            }
    	else if(window.ActiveXObject){ 
              reqXML = new ActiveXObject("Microsoft.XMLHTTP"); 
              if (reqXML) { 
                reqXML.onreadystatechange = BuildXMLResults; 
                reqXML.open("GET", url, true); 
                reqXML.send(); 
              } 
            } 
          } 
    
          function BuildXMLResults(){
            if(reqXML.readyState == 4){
              if(reqXML.status == 200){
    
                var xmlDoc = reqXML.responseXML.documentElement;
    	    var xRows = xmlDoc.getElementsByTagName('entry');
    
                var newTable = document.createElement('TABLE');
    	    var newBody = document.createElement('TBODY');
    	        
    	    newTable.appendChild(newBody);
    	       
    	    var newRow = document.createElement('TR');
    	       
    	    for(j=0;j<xRows[0].childNodes.length;j++){
    	      if (xRows[0].childNodes[j].nodeType != 1) continue;
    	      var container = document.createElement('TH');
    	      var theData = document.createTextNode(xRows[0].childNodes[j].nodeName);
    	      container.appendChild(theData);
    	      newRow.appendChild(container);
    	    }
    
                newBody.appendChild(newRow);
    	        
    	    for(i=0;i<xRows.length;i++){
    	      var newRow = document.createElement('TR');
    	      for(j=0;j<xRows[i].childNodes.length;j++){
    	        if(xRows[i].childNodes[j].nodeType != 1) continue;
    		var container = document.createElement('TD');
    		var theData = document.createTextNode(xRows[i].childNodes[j].firstChild.nodeValue);
    		container.appendChild(theData);
    		newRow.appendChild(container);
    	      }
    	      newBody.appendChild(newRow);
    	    }
    
      	    document.getElementById('results').innerHTML = "";
    	    document.getElementById('results').appendChild(newTable);
    
      	  } 
    	  else{
                alert("There was a problem retrieving the XML data:\n" + reqXML.statusText);
              }		
    	}
          }
    
        </script>    
      </head> 
      <body>
        <form name="Form1">
          <input name="user" type="text" onblur="GrabNumber()" />
          <div id="results"></div>
        </form>
      </body> 
    </html>
    The main problem is Mozilla is not building the table since it is returning zero rows with the following lines.
    Code:
    var xmlDoc = reqXML.responseXML.documentElement;
    var xRows = xmlDoc.getElementsByTagName('entry');
    Not sure if I am attacking this part correctly here.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Check that the XML doc is being served as "text/xml" - if not, you may not get a DOM
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I tested it with a plain old xml file and it worked.....ARGH...lol
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    I can get it to work with a vb.net page but not a classic ASP page. Strange.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •