470,619 Members | 2,003 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,619 developers. It's quick & easy.

Loading HTML using xmlhttprequest( )

I am trying to build a site using xmlhttprequest, so that the browser
never reloads. I want to pass the HTML info of the "navigation column"
, "content column" as a XML page from the server.
From the help on the net, I have managed to use xmlhhtprequest

succesfully to get the file from server and parse the XML. But I dont
know how to display the HTML info on the page.

When I just add the parsed HTML content from the xml to a <div>, it
just displays the text as HTML but not with the formating. ie the
display i get is " < b >this has to be in bold </ b > "

Can someone help me with this. How do I display it as formatted text.
Has it got anything to do with WYSIWYG.

Thanks in advance for the help.

Aug 8 '05 #1
2 2112


Arun wrote:
I am trying to build a site using xmlhttprequest, so that the browser
never reloads. I want to pass the HTML info of the "navigation column"
, "content column" as a XML page from the server.
From the help on the net, I have managed to use xmlhhtprequest

succesfully to get the file from server and parse the XML. But I dont
know how to display the HTML info on the page.

When I just add the parsed HTML content from the xml to a <div>, it
just displays the text as HTML but not with the formating. ie the
display i get is " < b >this has to be in bold </ b > "


Judging from that description it sounds as if you are best served with a
library taking care of that stuff so you might want to look into
libraries like Sarissa
<http://sarissa.sourceforge.net/>

As for your problem you haven't provided any code so I can only guess
that you are using the responseText you receive but then try to add it
to an element as a text node e.g.
someElement.appendChild(document.createTextNode(ht tpRequest.responseText));
as that way you simply create a text node and any markup in responseText
shows up as plain text.

If the responseText contains HTML markup then one rather easy and rather
cross browser way of having it parsed and inserted into the document is
setting the innerHTML property of an element e.g.
someElement.innerHTML = httpRequest.responseText;
If you don't have an element then you can create one e.g.
var div = document.createElement('div');
div.innerHTML = httpRequest.responseText;
document.body.appendChild(div);

There are other ways, at least with Mozilla and with Opera it makes
sense to send XHTML and then simply import nodes from responseXML
instead of using responseText.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 8 '05 #2
Thanks a lot Martin. I will try this out.
innerHTML method seems to be easier than using an API.

Aug 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by hbchai | last post: by
11 posts views Thread by paladin.rithe | last post: by
2 posts views Thread by www.gerardvignes.com | last post: by
5 posts views Thread by chakradhari.ashish | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.