Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to populate a combo box with ajax xml?

Status
Not open for further replies.

johannitis

Programmer
Sep 22, 2001
3
US
I am successfully pulling xml data from VFP and Webconnect and the success stops there. I want to populate a combo box with the xml, but can't seem to get it done. Here is a sample of the xml and some code that will return the list.

<?xml version = "1.0" encoding="UTF-8"
standalone="yes"?>
<officials>
<official>John Doe</official>
</officials>
<officials>
<official>Jane Doe</official>
</officials>
<officials>
<official>Jack Smith</official>
</officials>
<officials>
<official>Bill Williams</official>
</officials>

I create the ajax request object and call the url which will return an xml string.
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
If I put the following in an alert, it will show the xml:
alert(ajaxRequest.responseText);

However, if I try to determine how many elements or display and element with the following, it doesn't work. I get an alert that says object.
alert(ajaxRequest.responseXML.getElementsByTagName("officials")[0]);

Can anyone shed some light on this?
Do I need to format the xml differently?
 
make that
alert(ajaxRequest.responseXML.getElementsByTagName("officials")[0].text);

it still doesn't show anything but an error saying object required.

I have also tried:
var myrequest= ajaxRequest.responseXML;
alert(myrequest.getElementsByTagName("PLAYS")[0].text);

I used an xml file from an example and I still get the same error. This tells me the xml is not the problem.
Here's the other sample xml file:

<?xml version="1.0" standalone="yes"?>
<PLAYS>
<PLAY>
<TITLE>What the Butler Saw</TITLE>
<AUTHOR>Joe Orton</AUTHOR>
<YEAR>1969</YEAR>
</PLAY>
<PLAY>
<TITLE>The Ideal Husband</TITLE>
<AUTHOR>Oscar Wilde</AUTHOR>
<YEAR>1895</YEAR>
</PLAY>
</PLAYS>
 
I found the problem was in the content type of the response header. Once I changed it to "application/xml". The code works fine!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top