Loading HTML using xmlhttprequest( )

A

Arun

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.
 
M

Martin Honnen

Arun said:
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.

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(httpRequest.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.
 
A

Arun

Thanks a lot Martin. I will try this out.
innerHTML method seems to be easier than using an API.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top