title: getElementsByTagName () [0] is undefined
body: <p>I am trying my hand at some AJAX for the first time, and am running into an error. I've seen some people with similar problems, but after reading through them I still can't figure out what's wrong with my code.</p>
  
  <p>The problem I am getting is that <code>rf.getElementsByTagName("motd")[0]</code> is coming up as undefined.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>function refresh() {
      var url = document.getElementById("url");
      var req;
      if (window.XMLHttpRequest) {
          req = new XMLHttpRequest();
      } else {
          req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      req.onreadystatechange=function() {
          if (req.readyState==4 &amp;&amp; req.status==200) {
              var rf;
              if (window.DOMParser) {
                  parser = new DOMParser();
                  rf=parser.parseFromString(req,"text/xml");
              } else {
                  rf = new ActiveXObject("Microsoft.XMLDOM");
                  rf.async = false;
                  rf.loadXML(req); 
              }
              document.getElementById("result").innerHTML="&lt;div id=\"success\"&gt;"+
              rf.getElementsByTagName("motd")[0]+"&amp;nbsp;";
          } else {
              document.getElementById("result").innerHTML="&lt;div id=\"working\"&gt;Checking...&lt;/div&gt;";
          }
      }
      req.open("POST","g2mc_status.php",true);
      req.send("server="+url);
  }
  </code></pre>
  
  <p>And the XML I am trying to process (which is all the .php file is set to output right now):</p>
  
  <pre><code>&lt;minecraft server="mc.nrd.li" port="25565"&gt;
      &lt;motd&gt;NerdConglomerate&lt;/motd&gt;
      &lt;players&gt;
          &lt;online&gt;0&lt;/online&gt;
          &lt;maximum&gt;20&lt;/maximum&gt;
      &lt;/players&gt;
  &lt;/minecraft&gt;
  </code></pre>