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 05-14-2009, 12:01 AM   PM User | #1
otnj2ee
Regular Coder

 
Join Date: Apr 2007
Posts: 174
Thanks: 17
Thanked 0 Times in 0 Posts
otnj2ee is an unknown quantity at this point
AJAX and getElementById

I called the AJAX and it returns:

"<root><option id=\"test\" value=\"abc\">XYZ</option></root>"


In the front end::

if((req.readyState == 4 ) && req.status == 200) {

var answer =req.responseXML ;

alert(answer.getElementById('test').getAttribute("value") ); //It never displayed anything

//But

alert(answer.getElementsByTagName("option")[0].getAttribute("value") );

//worked and displayed the: abc
}

--Why does getElementById not work?


Thanks

Scott

Last edited by otnj2ee; 05-14-2009 at 12:03 AM..
otnj2ee is offline   Reply With Quote
Old 05-14-2009, 01:47 PM   PM User | #2
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
There is no "id" attribute defined in the XML DOM. It's not an HTML/XHTML document!

Google search : responseXML getElementById
w3schools XML DOM
bdl is offline   Reply With Quote
Old 05-14-2009, 06:05 PM   PM User | #3
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
If that is all that is returned, that is an invalid XML document.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 05-14-2009, 06:16 PM   PM User | #4
otnj2ee
Regular Coder

 
Join Date: Apr 2007
Posts: 174
Thanks: 17
Thanked 0 Times in 0 Posts
otnj2ee is an unknown quantity at this point
Thanks for the response.

Another question regarding to the <!DOCTYPE...

When is the <!DOCTYPE required?

For the AJAX returned string which does not have the <!DOCTYPE, but following processing of it has no problem at all.


Thanks

Scott
otnj2ee is offline   Reply With Quote
Old 05-14-2009, 07:08 PM   PM User | #5
otnj2ee
Regular Coder

 
Join Date: Apr 2007
Posts: 174
Thanks: 17
Thanked 0 Times in 0 Posts
otnj2ee is an unknown quantity at this point
To discuss with A1ien51, yes, the server returned:

"<root><option id=\"test\" value=\"abc\">XYZ</option></root>"

Now use AJAX, request.responseXML to follow-up, it actually works:

var ret = request.responseXML;

var value= ret.getElementsByTagName("option")[0].getAttribute("value");

alert(value); //This will display: "abc"


So it appears to me that the returned string is a valid XML string.


Thanks

Scott
otnj2ee 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 08:10 AM.


Advertisement
Log in to turn off these ads.