Results 1 to 2 of 2

Thread: how to handle ajax.responseXML?

  1. #1
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to handle ajax.responseXML?

    http://www.dynamicdrive.com/dynamici...jaxroutine.htm

    What's the difference between responseText and responseXML?

    when I get response from a jsp file, alert(ajax.responseText) ,it shows:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <employees>
        <employee name="J.Doe">
            <job>Programmer</job>
            <salary>32768</salary>
        </employee>
        <employee name="A.Baker">
            <job>Sales</job>
            <salary>70000</salary>
        </employee>
        <employee name="Big Cheese">
            <job>CEO</job>
            <salary>100000</salary>
        </employee>
    </employees>
    while use alert(ajax.responseXML), it shows [object].

    the point is that I need retrieve certain data in this XML, that is how to handle xmlObj = ajax.responseXML?
    xmlObj.getELementsByTagName("employee")[0].firstChild.data does not work.

    I found Microsoft.XMLDOM object can load (not open) an xml file into an xmlObj,which can be handle like xmlObj.getELementsByTagName("employee")[0].firstChild.data .

    So what is the difference between XMLDOM and XMLHTTP?
    Last edited by xnpeng; 03-23-2006 at 03:53 AM.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Yep, you'll want to use ajax.responseXML then. It returns a XML object that can be parsed using standard DOM methods. In the case of:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <employees>
        <employee name="J.Doe">
            <job>Programmer</job>
            <salary>32768</salary>
        </employee>
        <employee name="A.Baker">
            <job>Sales</job>
            <salary>70000</salary>
        </employee>
        <employee name="Big Cheese">
            <job>CEO</job>
            <salary>100000</salary>
        </employee>
    </employees>
    You can get to the first employee's salary by doing something like:

    Code:
    var xmlobj=ajax.responseXML
    var DoeSalary=xmlobj.getElementsByTagName("employee")[0].childNodes[1].nodeValue
    A handy reference with the various DOM element methods can be found here.

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
  •