Forum Moderators: open

Message Too Old, No Replies

javascript / ajax : req assistance with responseXML

inserting dynamic content as xml

         

sneaks

7:39 pm on Jan 29, 2007 (gmt 0)

10+ Year Member



i have been sort of fumbling through this ajax and am having a little problem. i want to append html data to current document using responseXML but when it displays i get [object]. if i use responseText then i get my html markup as text...

heres my code:


<script type="text/javascript">
var req;
var language;
var section;
var subsection;
var theGet;
function ajaxLoadContent( language, section, subsection )
{
theGet = './process.php?language=' + language + '&section=' + section + '&subsection=' + subsection;
id = section + 'Content';
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest)
{
req = new XMLHttpRequest();
}
// branch for activeX
else if (window.ActiveXObject)
{
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.onreadystatechange = processReqChange;
req.open("GET", theGet, true);
req.send( null );
}
function processReqChange()
{
// only if req shows "complete"
if (req.readyState == 4)
{
// only if "OK"
if (req.status == 200)
{
var node = document.createTextNode( req.responseXML );
document.getElementById( id ).appendChild( node );
}
else
{
alert ("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
oldIdMarker = id;
}
</script>

thx!

daveVk

1:07 am on Jan 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if returned data is valid xml, that is xhtml you could try
document.getElementById( id ).appendChild( responseXml.documentElement )

if not then document.getElementById( id ). innerHTML = responseText?

createTextNode expects text assumably without markup?

cmarshall

9:42 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I PMed you something. Good luck.