Problem with XMLHttpRequest.responseXML

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robezy
    New Member
    • Feb 2010
    • 3

    Problem with XMLHttpRequest.responseXML

    Hi,

    I'm pulling my hair for some time with this problem today. Will greatly appreciate if some one could provide me a solution.

    I'm using ajax to get a list of categories to be populated in a dropdown.

    My main code is below.

    Code:
    function makeRequest() {
    
                    if (window.ActiveXObject)
                            return new ActiveXObject("Microsoft.XMLHTTP");
                    else if (window.XMLHttpRequest)
                            return new XMLHttpRequest();
                    else {
                            alert("Your browser does not support AJAX.");
                    return null;
                    }
    
    }
    
    
    
     var http = makeRequest();
    
     function sendRequest(url, callbackfn) {
             http.open('get', url);
             http.onreadystatechange = callbackfn;
             http.send( null );
     }
    Problem is in the next section of code.

    Code:
    var response = http.responseXML;
    var row = response.getElementsByTagName('topic');
    This works fine in FF, Opera, Safari, Chrome showing the dependable dropdowns, but not in IE. the row is empty when checked in ie.

    when i do an alert
    Code:
    alert(row.length);
    i get zero as length. i have no clue why the length becomes zero. IE shows no error message also.

    the xml returned by the php script is given below.
    Code:
    <?xml version="1.0"?>
    <topics>
      <topic id="1" title="Arithmetic"/>
      <topic id="2" title="Algebra"/>
      <topic id="3" title="Geometry"/>
      <topic id="4" title="Word Problems"/>
      <topic id="5" title="Miscellaneous"/>
    </topics>
    please give me some advice
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Are you getting the xml when you aler the variable "response" ?

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • robezy
      New Member
      • Feb 2010
      • 3

      #3
      try {
      var response = http.responseXM L;
      alert(response) ;
      var row = response.getEle mentsByTagName( 'topic');
      } catch(exception ) {
      alert('An execption occured.' + exception.messa ge);
      }
      In ie i'm getting an alert window showing [object]..

      Can anybody give a clue....

      thanks

      Comment

      • robezy
        New Member
        • Feb 2010
        • 3

        #4
        Code:
        var response = http.responseText;
        alert(response);
        will show me the xml file.

        Code:
        var response = http.responseXML;
        alert(response);
        gives [object] as o/p..

        thanks..
        Robert

        Comment

        Working...