title: Javascript AJAX function not working properly
body: <p>I have a function that sends a GET request to a php script and checks if the script returned any output. It works great, but when I try to add another function that checks for something similar, both of them fail. What am I missing?</p>
  
  <pre><code>    function checkUsername(usr,n) {
          var user = usr.val(), xmlhttp;
  
          //var str = document.getElementById('email').value;
          if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
            }
          else
            {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
          xmlhttp.onreadystatechange=function()
            {
            if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
              {
              //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                  if (xmlhttp.responseText != "") {
                      usr.addClass( "ui-state-error" );
                      updateTips( n );
                      return false;
                  }
                  else {
                      return true;
                  }
              }
            }
          xmlhttp.open("GET","ajaxValidate.php?type=user&amp;q="+user,true);
          xmlhttp.send();
  
      }
  </code></pre>
  
  <p>The above works perfectly, when adding this function, none of them work:</p>
  
  <pre><code>    function checkEmail(em,n) {
          var email = em.val(), xmlhttp;
  
          //var str = document.getElementById('email').value;
          if (window.XMLHttpRequest)
            {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
            }
          else
            {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
          xmlhttp.onreadystatechange=function()
            {
            if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
              {
              //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                  if (xmlhttp.responseText != "") {
                      em.addClass( "ui-state-error" );
                      updateTips( n );
                      return false;
                  }
                  else {
                      return true;
                  }
              }
            }
          xmlhttp.open("GET","ajaxValidate.php?type=email&amp;q="+email,true);
          xmlhttp.send();
      }
  </code></pre>