2 out of 11 rated this helpful - Rate this topic

responseXML property

[This documentation is preliminary and is subject to change.]

Retrieves the response body as an XML Document Object Model (DOM) object.

Syntax

JavaScript

p = object.responseXML

Property values

Type: Object

The response body.

Standards information

Remarks

Use QueryInterface to convert the returned pointer p into IXMLDOMDocument.

For properties and methods supported by p, refer to the documentation of IXMLDOMDocument/DOMDocument Members.

responseXML was introduced in Windows Internet Explorer 7.

Examples

The following example uses the XML DOM to display the response body:


var oReq = new XMLHttpRequest();
oReq.open("GET", "http://localhost/books.xml", false);
oReq.send();
console.log(oReq.responseXML.xml);

See also

XMLHttpRequest
Reference
responseBody
responseText

 

 

Build date: 2/14/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Use of responseXML on client-side
if you try to use the object request from webform to return a xml file and use it in javascript as responseXML, you need to clear the content of the aspx file

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="mywebpage_xml.aspx.vb" Inherits="mywebpage"%>


this shall be the only line that your web page must content.


and in the vb code you need to do something like this


<code>
       Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
             Response.ContentType = "text/xml"

             'if you wish you could get the information from a db
             Dim str As String
             str = str & "<concept>"
             str = str & "<id_concept>" & 25 & "</id_concept>"
             str = str & "<num_concept>" & 35 & "</num_concept>"
             str = str & "<mydescription>" & "my description" & "</mydescription>"
             str = str & "<tax>" & 16 & "</tax>"
             str = str & "<ret_percent>" & 10 & "</ret_percent>"
             str = str & "</concept>"            
             
             Response.Write(str)
            End If
      End Sub
</code>


you can now use it in javascript on client-side I'm using it in framework 1.1 and works fine, you could use it in any framework

in your aspx file declare a asp:textbox


    <asp:textbox id="txtIdMov" runat="server" onchange="getMovInfo();"  />

and add the onchange property to get the information from the xml on the mywebpage.aspx

Functions on javascript

function getMovInfo() {
      var tipomov = document.getElementById(txtIdMov).value;
    if ( tipomov != '' ) {
               var url = "mywebpage_xml.aspx"
               http.open("GET", url, true);
               http.onreadystatechange = setMovValues; 
               http.send(null);
      }
}


function setMovValues() {
             if (http.readyState == 4)
             {
                       if (http.status == 200) { 
        document.getElementById('txtIdMov').value = http.responseXML.getElementsByTagName('id_concept')[0].text; 
        document.getElementById('txtDescription').value = http.responseXML.getElementsByTagName('mydescription')[0].text;
        document.getElementById('txtTax').value = http.responseXML.getElementsByTagName('tax')[0].text;
                      }
              }
}

var http = getHTTPObject(); 

 function getHTTPObject() {
        var xmlhttp;
        try {
                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
                 try {
                           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                 } catch (E) { xmlhttp = false; }
        } 
       
       if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
                  xmlhttp = new XMLHttpRequest();
       }
      return xmlhttp;
}