bruceallen61
02-02-2010, 06:51 AM
I'm implementing/learning some ajax things, but I'm a bit stuck on how to work with the xml result. I'm basing my code off Dynamic Drives ajax examples.
http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm
The text version comes back fine and displays all the relevant echoed text from the server, but when the XMl version echos back I simply get the DOM. The examples on Dynamic drive don't include anything for working
client side with the DOM and I've scoured the net and tried numerous things in an attempt to work directly
with the return xml.
function processGetPost()
{
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4)
{ //if request of file completed
document.getElementById("img-l").className='nothere2';
document.getElementById("btncc").className='there';
if (myajax.status==200 || window.location.href.indexOf("http")==-1)
{ //if request was successful or running script locally
if (myfiletype=="txt")
{
alert(myajax.responseText)
}
else
{
alert(myajax.responseXML);
....
Result is alert message box: [object Document]
So the question is how do I work directly with the xml/read it.
Say my xml looked something like this...
<xmlresponse>
<result><? echo $result ?></result>
<code><? echo $code ?></code>
<fname><? echo $fname ?></fname>
<lname><? echo $lname ?></lname>
</xmlresponse>
How do I work with the XML DOM in order to display/get/work with fname?
http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm
The text version comes back fine and displays all the relevant echoed text from the server, but when the XMl version echos back I simply get the DOM. The examples on Dynamic drive don't include anything for working
client side with the DOM and I've scoured the net and tried numerous things in an attempt to work directly
with the return xml.
function processGetPost()
{
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4)
{ //if request of file completed
document.getElementById("img-l").className='nothere2';
document.getElementById("btncc").className='there';
if (myajax.status==200 || window.location.href.indexOf("http")==-1)
{ //if request was successful or running script locally
if (myfiletype=="txt")
{
alert(myajax.responseText)
}
else
{
alert(myajax.responseXML);
....
Result is alert message box: [object Document]
So the question is how do I work directly with the xml/read it.
Say my xml looked something like this...
<xmlresponse>
<result><? echo $result ?></result>
<code><? echo $code ?></code>
<fname><? echo $fname ?></fname>
<lname><? echo $lname ?></lname>
</xmlresponse>
How do I work with the XML DOM in order to display/get/work with fname?