Forum Moderators: open
This may be a very easy question, but for some reason I haven't been able to find the answer in the last hour or so of looking.
I'm a long-time web developer, but I'm brand new to Ajax. I'm working on a site that opens various forms in a floating Lightbox div. These forms are complete html pages, so non-js users just load it in their browser.
So, the Ajax request returns an html page. But, I need to modify that page/form based on which elements are present in the opening/parent page.
My question is, can I just pop the Ajax requestText into a standard JS DOM somehow, so I can use all the nifty methods for traversing the document tree, or do I have to parse the text directly? It seems like this should be easy to do, but I can't find the answer.
Thanks in advance.
function getResponse(e) {
div=document.createElement('div');
div.innerHTML=e.responseText;
alert(div.firstChild);
// use this to list all first-level elements.
//for (var i=0,c;c=div.childNodes[i];i++) alert(c.tagName)
alert(div.innerHTML)
}
All the elements are immediate childs of the div element (but <head> and <body> disappear).
IE get rids of everything that is not inside <body> (<head>, <title>, <meta>). Mozilla keeps what was inside the <head> element.
responseXML is not populated. ;)
I did some experimenting, and if a text/xml content-type is returned, it does get populated
I'm trying to avoid doing anything different on the server side, i.e. changing the content/type. These pages are supposed to load in a Lightbox for JS users, and in a full browser window for non-JS users. So, keeping them plain xhtml seems simpler.
Thanks again for the tutelage.