473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem Getting Elements By Tag Name

Hello all,

I'm using XMLHttpRequest to get data from a PHP script. Everything
seems to be working... if I look at the result of "new
XMLSerializer().serializeToString(response)" with response being
"response = request.responseXML" I get the correct xml data. However,
when I try to do something like "var result =
response.getElementByTagName("result")" it doesn't work.

Any suggestions as to what's going on?

Sep 23 '06 #1
10 12589


Bryan wrote:

I'm using XMLHttpRequest to get data from a PHP script. Everything
seems to be working... if I look at the result of "new
XMLSerializer().serializeToString(response)" with response being
"response = request.responseXML" I get the correct xml data. However,
when I try to do something like "var result =
response.getElementByTagName("result")" it doesn't work.
What happens exactly? getElementsByTagName returns a node list so you
should check result.length. If it is 0 then no elements were found.
We would need to see the XML to tell more.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 23 '06 #2
The returned XML looks like this:

<?xml version="1.0"?>
<results><cities><city id="1" name="Albuquerque" state="NM" desc="Duke
City" lat="0" lng="0"/></cities><result status="success"/></results>

I get this when I do the following:

var response = request.responseXML;
alert(new XMLSerializer().serializeToString(response));

I then do the following:

var result = response.getElementByTagName("result");
alert(result.length);

However, for some reason the alert never even pops up... like the code
never gets past assigning data to the result variable.

Thanks for your assistance.

Sep 24 '06 #3


Bryan wrote:

var result = response.getElementByTagName("result");
alert(result.length);

However, for some reason the alert never even pops up... like the code
never gets past assigning data to the result variable.
Check the JavaScript console (or error console) then, tell us which
error messages it shows, which browser exactly does that, whether other
browsers give the same errors.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 24 '06 #4
The JavaScript Console gives me the following error...

Error: response.getElementByTagName is not a function

Sep 24 '06 #5
Sorry, forgot to say that this is happening in Firefox 1.5.0.7

I'm developing on a linux laptop, so I cannot test using another
browser, such as IE.

Sep 24 '06 #6


Bryan wrote:
The JavaScript Console gives me the following error...

Error: response.getElementByTagName is not a function
Right that method in the DOM is called getElementsByTagName and not
getElementByTagName. So
response.getElementsByTagName('element-name')
will do.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 24 '06 #7
If I use

var result = response.getElementsByTagName("result")[0]

rather than

var result = response.getElementByTagName("result") <-- no "s" on
Element

everything works fine. However, I thought there was a function called
getElementByTagName that just grabbed the first occurance... not so?

Sep 24 '06 #8

Bryan wrote:
However, I thought there was a function called
getElementByTagName that just grabbed the first occurance... not so?
No. MSXML 3 as used by IE 6 has a method selectSingleNode which takes an
XPath expression and returns the first matching node. But the W3C Core
DOM only has getElementsByTagName.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 24 '06 #9
getElementsByTagName returns an array. So just reference the first
occurance of the "result" element:

getElementsByTagName[0]


Martin Honnen wrote:
Bryan wrote:
However, I thought there was a function called
getElementByTagName that just grabbed the first occurance... not so?

No. MSXML 3 as used by IE 6 has a method selectSingleNode which takes an
XPath expression and returns the first matching node. But the W3C Core
DOM only has getElementsByTagName.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 25 '06 #10
Sorry, that would be:

getElementsByTagName("result")[0]

Matthom wrote:
getElementsByTagName returns an array. So just reference the first
occurance of the "result" element:

getElementsByTagName[0]


Martin Honnen wrote:
Bryan wrote:
However, I thought there was a function called
getElementByTagName that just grabbed the first occurance... not so?
No. MSXML 3 as used by IE 6 has a method selectSingleNode which takes an
XPath expression and returns the first matching node. But the W3C Core
DOM only has getElementsByTagName.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 25 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
8
by: Sowen | last post by:
Hi, I have an object "elem", there are only simple functions inside, like setName, getName, and three constructors Now I have another class "Base", need an array of elem to initialize class...
1
by: Phil Powell | last post by:
function populateWithPics(folder) { if (folder.value != '') { monthIndex = folder.name.substring(folder.name.indexOf("'") + 1, folder.name.indexOf('\]') - 1); indexArray =...
11
by: ned786 | last post by:
Hello, I'm trying to solve an XSLT problem, and I'm hoping someone can give a little guidance. I am transforming XML to HTML. Here's an example of the XML file I'm dealing with, greatly...
6
by: Michael | last post by:
Hi All, I need a few suggestions. I have the following XML segment: <LookUp> <ControlType>CheckBoxGroup</ControlType> <DBField>LastMedDate</DBField> <ControlName>cmbGoal1</ControlName> <Values...
11
by: Marcus Jacobs | last post by:
Dear Group I have encountered a problem with fclose and I am wondering if anyone could provide some insight about this problem to me. Currently, I am working on a small personal project that is...
1
by: infiniti | last post by:
Hi, I am trying to transform this xml section using xsl, but there is a glitch in the xsl file which I do not know how to rectify. Any help is appreciated. XML: <?xml version="1.0"...
7
by: Trickynick1001 | last post by:
Hi, a newbie here. I don't have a real firm grasp on the idea of Javascript, as I'm used to programming in Qbasic and C. I'm not used to OOP. Anyway, I really don't have any idea what the...
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
0
by: jianxin9 | last post by:
Hi everyone, I don't have a lot of experience with ASP and I was hoping someone could help me. I want to use our ASP form along with some javascript code to create a form where our patrons can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.