title: using Ajax and Javascript - executing both if/else statements
body: <p>Hi im new here so I hope I did this right.. I'm reading the Ajax for Dummies book (read the php one years ago and it was great so giving this one a shot) and I'm stuck on the first real Ajax program.. It took me forever to get it to actually find the text file but while attempting to find out just where the problem was in the program I noticed an issue that I don't understand. </p>
  
  <p>At one point it checks to see if readyState == 4 AND status == 200 and if that's false then it displays the alert message of "nope" -- it always alerts "nope" as well as executes the other part of the if statement.. why? (listed below is the only code i've got so far - no other files that could be calling the function) if I take the "else" statement out it works fine but this could be a problem for me later on and I want to know why it's doing it... thanks a lot!</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
  &lt;meta content="text/html;charset=utf-8" http-equiv="Content-Type"&gt;
  &lt;meta content="utf-8" http-equiv="encoding"&gt;
  &lt;title&gt;Ajax at work&lt;/title&gt;
  &lt;script language = "JavaScript"&gt;
  var XMLHttpRequestObject = false;
  if (window.XMLHttpRequest) 
  {
      XMLHttpRequestObject = new XMLHttpRequest();
  } 
  else if (window.ActiveXObject) 
  {
      XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  function getData(dataSource, divID)
  {
      if(XMLHttpRequestObject) 
      {
          var obj = document.getElementById(divID);
          XMLHttpRequestObject.open("GET", dataSource, true);
          XMLHttpRequestObject.onreadystatechange = function()
          {
              if (XMLHttpRequestObject.readyState == 4 &amp;&amp; XMLHttpRequestObject.status == 200)
              {
                  obj.innerHTML = XMLHttpRequestObject.responseText;
              } 
              else 
              {
                  alert("nope");
              }
          }
          XMLHttpRequestObject.send(null);
      }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;H1&gt;Fetching data with Ajax&lt;/H1&gt;
      &lt;form&gt;
          &lt;input type="button" value="submit" onclick="getData('http://localhost/AV/data.txt', 'targetDiv')"&gt;
      &lt;/form&gt;
      &lt;div id="targetDiv"&gt;
          &lt;p&gt;The fetched data will go here.&lt;/p&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>