Use innerHTML. However, be aware that certain browser
<mumble>IE</mumble> will not fully expand innerHTML for certain
elements.
I'm not sure as to what Craig means, but basically if the thing you are
returning is HTML and not XML, then don't treat it as XML at all. Just
use xmlhttptransport.resonseText (notice responseText rather than
responseXML). This will simply get the plain text that the server
returned and not try to make any XML object out of it or anything. This
way you can just do something like:
var div = document.createElement('div');
div.innerHTML = client.responseText;
Then you need to insert the div element somewhere. Or if you're
updating a currently existing element it's even easier. But yeah, don't
bother with XML unless the data you're returning is XML.
If your problem was that you have some XML that you're returning and
there is some HTML embedded within that XML, then you have a different
problem. I'm not very XML savvy, but I thin what you do is get the XML
document by using xmlhttptransport.responseXML and then navigating to
the XML tag with the HTML inside it and using somethgin like nodeText
or maybe nodeValue or somethgin like that? Sorry, I don;t really know.
Hope this helps, though,
Al.
On Dec 14, 9:14 pm, "junee" <junai@yahoo.com> wrote:
> Hi,
> I am new to Ajax. if you can help me,
> i will explain it.
> In JavaScript, using XMLHttpRequest, brought an xml file from server,
> but it really contain some HTML code fragment, ie a DIV and its inner
> things.
> i want to insert this DIV tag directly into HTML page, but i cant. i
> did as follows, it is not full
> var client; // assigned a XMLHttpRequest and requested a xml file and
> succeeded
> .......
> .......
> var xmlDoc=client.responseXML;
> .......
> .......
> var temp=xmlDoc.getElementByTagName("div");
> var mydiv=temp[0]; // it have only
> one <div> ....</div>
> when i appended this mydiv to HTML it only shows its text,
> concatenating all text within its child tags
> i used Firefox browser.
> is it possible to directly import HTML tags from XML file and insert
> into HTML page.
> is above method correct, if not how can do it
> please help me.
Hi
use this
var temp=xmlDoc.getElementsByTagName("div");
var mydiv.innerHTML=getdata(temp[0]);
function getdata()
{
return (node.textContent|| node.innerText|| node.Text);
}
Regrds'
Atul
----- Original Message ----
From: junee <junai
@yahoo.com>
To: AJAX World <ajax-world@googlegroups.com>
Sent: Thursday, December 14, 2006 1:14:59 PM
Subject: [AJAX World] Can I convert XML element to HTML, please help
Hi,
I am new to Ajax. if you can help me,
i will explain it.
In JavaScript, using XMLHttpRequest, brought an xml file from server,
but it really contain some HTML code fragment, ie a DIV and its inner
things.
i want to insert this DIV tag directly into HTML page, but i cant. i
did as follows, it is not full
var client; // assigned a XMLHttpRequest and requested a xml file and
succeeded
.......
.......
var xmlDoc=client.responseXML;
.......
.......
var temp=xmlDoc.getElementByTagName("div");
var mydiv=temp[0]; // it have only
one <div> ....</div>
when i appended this mydiv to HTML it only shows its text,
concatenating all text within its child tags
i used Firefox browser.
is it possible to directly import HTML tags from XML file and insert
into HTML page.
is above method correct, if not how can do it
please help me.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
thank you for reply.
i did it without problem. i think both Craig and AI suggested same
thing.
because of lack of knowledge i didnt get what Craig proposed,
fortunately AI explained it well
i did it as AI shown, thanks, it really took only two line change.
also Atul shown same. but i have only one div. so i did as AI.
when i have more tags, i think Atul's will be useful.
again thanks to all