Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-07-2007, 10:47 PM   PM User | #1
acroporas
New Coder

 
Join Date: Mar 2007
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
acroporas is on a distinguished road
Help getting data out of responseXML

I want my javascript to recieve an xml page containing two bits html code to insert into various places in the page.

example xml page
Code:
 <?xml version="1.0" ?> 
  <root>
     <image><img src="images/image1.jpg" class="imageclass" /></image> 
    <exif>
<table>
<tr><td>Head</td><td>Data</td>
.....
<tr><td>Head</td><td>Data</td>
</table>
    </exif>
</root>
I am pretty confident that I am sucessfully reciving the file as I can get the following.

window.alert(ajaxreq.responseXML);
// displays "[object XMLDocument]" in firefox
// displays "[object]" in IE7

window.alert(ajaxreq.responseXML.xml);
// displays the contents of the xml file in IE7
// displays "undefined" in firefox

Seems so good so far....
But that is far as I can get.

When I try
window.alert(ajaxreq.responseXML.getElementsByTagName("image")[0].nodeValue);
//returns null in both IE and Firefox.....

Am I doing something wrong? How do I get the contents of <image> and <exif> nodes so that I can insert them into my page?
acroporas is offline   Reply With Quote
Old 07-08-2007, 08:38 PM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Code:
var xmlDoc = ajaxreq.responseXML.documentElement;
alert(xmlDoc.getElementsByTagName("image")[0].nodeValue);
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:29 PM.


Advertisement
Log in to turn off these ads.