XML : Unable to get attribute value from xml tag

I am new to AJAX and XML.

I have the following XML:

  <rsp stat="ok">  <auth>  <token>123-123</token>  <perms>read</perms>  <user nsid="id" username="user_name" fullname="Full Name"/>  </auth>  </rsp>    

I have the following code:

   function readXML(xml)      {          var xmlDoc = xml.responseXML;          var x = xmlDoc.getElementsByTagName("user");          document.getElementById("dummy").innerHTML= x.getAttribute("username"));  window.location.replace("path/info.php?username="+ x.getAttribute("username"));      }        var xhttp = new XMLHttpRequest();      xhttp.onreadystatechange = function()      {          if(xhttp.readyState==4 && xhttp.status==200)          {              readXML(xhttp)          }      }        xhttp.open("GET", <?php echo ($url);?>, true);      xhttp.send();    

I am unable to get any attribute(nsid, username, fullname) of xml tag. How can I fix this?

No comments:

Post a Comment