spark wrote:
[color=blue]
> I have been experimenting with xmlhttprequest. (I am a javascript
> newbie, but familiar with programming with VB, Perl, and some PHP.) I
> am trying to see if it's possible to receive html snippets back from a
> request, and then insert that snippet into the target page; for example,
> getting back a set of <ul> lists within lists, or a set of <option>
> tags, which could then be added to a page's extent lists, or to select
> inputs.
>
> I'm trying to do this by setting the content-type header in the returned
> data to text/xml, and I'm able to insert the nodes into the target page;
> but then they will not be formatted with any css page I may have set
> within the target page. Taking the aforementioned <ul> list, if the
> target page references a css page with some layout rules for ul, the
> inserted <ul> nodes aren't formatted using these rules.[/color]
Make sure you send elements in the XHTML namespace e.g.
<ul xmlns="http://www.w3.org/1999/xhtml">
<li>Kibo</li>
</ul>
then with Mozilla you can do:
[color=blue]
> if (xmlhttp) {
> xmlhttp.open("GET", "[command]",true);
> xmlhttp.onreadystatechange=function() {
> if (xmlhttp.readyState==4) {
> var insertHere = document.getElementById('writeroot');
> var respDoc = xmlhttp.responseXML;
> insertHere.parentNode.insertBefore(respDoc.childNo des
> [0].cloneNode(true),insertHere);[/color]
insertHere.parentNode.insertBefore(
insertHere.ownerDocument.importNode(respDoc.docume ntElement, true),
insertHere
);
That should then also work with other browsers having a common DOM
implementation for HTML and XML but with IE/Win that approach is not
possible, IE doesn't have an XML DOM implementation but uses MSXML to
parse XML and you can't move nodes from the MSXML XML DOM implementation
to the IE HTML DOM implementation. So with IE you are left to using
responseText and insert that e.g.
someElement.innerHTML = xmlhttp.responseText;
or
someElement.insertAdjacentHTML('beforeEnd', xmlhttp.responseText);
or you would need to write importNode for IE e.g. walk the MSXML XML DOM
and create all nodes as needed in the IE HTML DOM. But for instance the
Sarissa project suggests that IE with innerHTML performs better than an
attempt to implement importNode with DOM createXXX method calls so there
importNode is "implemented" by creating a div, setting its innerHTML and
then using the child nodes.
The Sarissa project is here:
<http://sarissa.sourceforge.net/>
--
Martin Honnen
http://JavaScript.FAQTs.com/