Results 1 to 3 of 3

Thread: Working with Client Javascript XML DOM

  1. #1
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Working with Client Javascript XML DOM

    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/dynamici...jaxroutine.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?

  2. #2
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I managed to figured this out eventually, but I'm running into a snag with IE. Anyone have any ideas. Below is the working code in FF/chrome, doesn't seem to operate correctly in IE 6 or 8, havent tried other versions of IE yet.

    //XML

    <xmlresponse>
    <transaction>
    <result><? echo $result ?></result>
    <code><? echo $code ?></code>
    <fname><? echo $fname ?></fname>
    <lname><? echo $lname ?></lname>
    </transaction>
    </xmlresponse>

    alert(myajax.responseXML);

    //The code

    var xmlobj=myajax.responseXML

    //working in FF & chrome
    alert(xmlobj.getElementsByTagName("transaction")[0].childNodes[1].textContent); //result ok
    alert(xmlobj.getElementsByTagName("transaction")[0].childNodes[3].textContent); //code ok
    alert(xmlobj.getElementsByTagName("transaction")[0].childNodes[5].textContent); //fname ok
    alert(xmlobj.getElementsByTagName("transaction")[0].childNodes[7].textContent); //lname ok


    When I attempt to get the result in a message box in IE. I get the first message/alert box displaying [object]. Then the following message boxes don't display.

    Anyone know why this is?

  3. #3
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    anyone have any ideas on this?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •