object returns zero length
Posted: Wed Mar 26, 2008 11:42 pm
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
working with a AJAX tutorial book that builds an XML file and then parses it.
All the functions are working, but when I call the object containing the xml file it shows a zero length.
the xml file in question:
the javascript function that calls the data:
Now I know that all the other functions are working because I was able to send through some test data. The only problem seems to be that the following elements are zero length, and I can't think of anything that would cause the problem.
When I try to retrieve the length of the elements they show zero.
Can anyone suggest what I can do to troubleshoot this problem?
thank You
Kevin
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
working with a AJAX tutorial book that builds an XML file and then parses it.
All the functions are working, but when I call the object containing the xml file it shows a zero length.
the xml file in question:
Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="YES" ?>
<response>
<books>
<book>
<title>
Building responsive web applications with AJAX and PHP
</title>
<isbn>
1-904811-82-5
</isbn>
</book>
</books>
<books>
<book>
<title>
Beggining PHP 5 and MYSQL E-Commerce from Novice to Professional
</title>
<isbn>
1-59050-392-8
</isbn>
<book>
</books>
</response>
Code: Select all
//handles the response received from the server
function handleServerResponse(){
//read the message from the server
var xmlResponse = xmlHttp.responseXML;
//obtain the xml's document element
xmlRoot = xmlResponse.documentElement;
//obtain arrays with book titles and ISBNs
titleArray = xmlRoot.getElementsByTagName("title");
isbnArray = xmlRoot.getElementsByTagName("isbn");
//generate html output
var html = "";
//iterate through the arrays and create an HTML structure
for(var i=0; i<titleArray.length; i++){
html += titleArray.item(i).firstChild.data + ", " + isbnArray.item(i).firstChild.data + "<br/>";
}
//obtain a reference to the <div> element on the page
myDiv = document.getElementById("myDivElement");
//display the html output
myDiv.innerHTML = "Server says: <br />" + html;
}
Code: Select all
//obtain arrays with book titles and ISBNs
titleArray = xmlRoot.getElementsByTagName("title");
isbnArray = xmlRoot.getElementsByTagName("isbn");
Can anyone suggest what I can do to troubleshoot this problem?
thank You
Kevin
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: