By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,623 Members | 1,991 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,623 IT Pros & Developers. It's quick & easy.

Howto access xmlHttp.responseText as document.getElementByTagName, etc...

P: 4
Howto access xmlHttp.responseText as document.getElementByTagName ?

If I access a .html page through the xmlHttp, how can I use the functions .getElementsByTagName and .getElementById on the data found in the xmlHttp.responseText?

(the .responseXML returns null, and the responseText is simple text, of course containing valid html code)
Jun 21 '07 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
Either have valid XML or you could add it to the document e.g. a hidden div and then parse it.
Jun 21 '07 #2

ronnil
Expert 100+
P: 134
Howto access xmlHttp.responseText as document.getElementByTagName ?

If I access a .html page through the xmlHttp, how can I use the functions .getElementsByTagName and .getElementById on the data found in the xmlHttp.responseText?

(the .responseXML returns null, and the responseText is simple text, of course containing valid html code)
What I'm reading:

You want to download an html page via xmlHttp, the elements inside that that downloaded html page you want to access via document.getElementByID

right?

This is not doable, per say, since you don't download htmlpages with htmlHttp but you download data, either in string or xml.

What i think acoder means is:

you make an empty div tag.
you download your htmlpage and retrieve it with the responseText property.
you then set your div tag's innerHTML=responseText

now, for browser compability reasons i suggest you use an iframe instead of a div tag :) for example, if your html page is valid xhtml you will have header and such defined, that could make browsers confused... this won't happen in an iframe ;)
Jun 21 '07 #3

P: 4
Actually I wanted to download a html template and an xml file and combine them in the browser :P I don't know if this is a good idea, but I guess it could be done.

Now I need to mostly replace the actual page in the browser with the one downloaded and then fill it wit data from the xml.

Gimme your critics on this idea :)
Jun 21 '07 #4

rnd me
Expert 100+
P: 427
Actually I wanted to download a html template and an xml file and combine them in the browser :P I don't know if this is a good idea, but I guess it could be done.

Now I need to mostly replace the actual page in the browser with the one downloaded and then fill it wit data from the xml.

Gimme your critics on this idea :)
yes, it is a good idea.
so good that there is already a major system for doing just that:
XSLT.

think of it as CSS on steroids.

you can not only apply html styles to the xml data, but you can sort, filter, modify, combine severy files, etc.

be sure read up on it, it sound like it would be right up your alley.
Jun 21 '07 #5

acoder
Expert Mod 15k+
P: 16,027
What i think acoder means is:

you make an empty div tag.
you download your htmlpage and retrieve it with the responseText property.
you then set your div tag's innerHTML=responseText
Yes, that's right.
now, for browser compability reasons i suggest you use an iframe instead of a div tag :) for example, if your html page is valid xhtml you will have header and such defined, that could make browsers confused... this won't happen in an iframe ;)
Yes, that's a better solution. Thanks!
Jun 22 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.