I am new to AJAX, and I am trying to parse out an XML response from
the server. The code works perfectly in IE, but does not work in
FireFox. Here is my code. Can anyone suggest the issue or an
alternative.
Thanks in advance.
Albert
function processGetStates() {
var frmState = document.getElementById(wa_state);
removeAllOptions(frmState);
if (req.readyState == 4) {
if (req.status == 200) {
// alert(req.responseText);
xmlDoc = req.responseXML;
// var root = xmlDoc.getElementsByTagName("STATES")[0];
// alert(root.length);
var states = xmlDoc.getElementsByTagName("item");
alert(states.length);
// var state = states[0].getElementsByTagName("STATE")
[0].childNodes[0].nodeValue;
// var description =
states[0].getElementsByTagName("DESCRIPTION")
[0].childNodes[0].nodeValue;
// alert(state + description);
// alert(states.length);
for (var i=0; i<states.length; i++)
{
var state = states.item(i).getElementsByTagName("STATE")
[0].childNodes[0].nodeValue;
var description =
states.item(i).getElementsByTagName("DESCRIPTON")
[0].childNodes[0].nodeValue;
addOption(frmState, state, description);
}
// alert(req.responseText);
}
}
}
as you can see I have tried everything and none of these syntax works
in FireFox.
Thanks.
Albert
> as you can see I have tried everything and none of these syntax works
> in FireFox.
Post a URL to the XML document you are trying to read out data from and
explain which data exactly you are looking for. If you don't have a URL
then post a relevant sample of the XML, cut to a minimum but still
complete enough to show the structure.
--
Martin Honnen
http://JavaScript.FAQTs.com/
I notice you are searching for tags with both upper- and lowercase names.
Since element and attribute names are case sensitive in XML, could it be
that you don't find matching elements because all elements in the
received document have lowercase names, while you are looking for
elements with uppercase names?
--
Regards,
Roland
how much code you have to write?
if his more than trivial code, i suggest you to search for a function
that read a xml tree, and generate a javascript object with all the
information mirrored (json alike). or directly, use json.
json is easier to read and to use, less error prone
also, json will automatically handle for your the data encoding (UTF8)
in a transparent js to js way.
good code sould be easy to write and read, and not this mess where the
syntax obscure the algorithm.
I am totally pro-XML everywhere else, but parsing in js.
have you checked whether the response header "Content-Type" is "text/xml"?
and you can get the value by:
xmlResponse.getResponseHeader("Content-Type");
thanks
luke
在 Tue, 9 Sep 2008 16:54:27 -0700 (PDT) 时, ajis...@gmail.com 写了:
--