title: Uncaught TypeError: Cannot read property 'responseText' of undefined
body: <p>I got a register page on my website, The problem is that i started to get this errors:</p>
  
  <p><strong>Uncaught TypeError: Cannot read property 'responseText' of undefined</strong></p>
  
  <p><strong>Refused to set unsafe header "Content-length" register.php:1</strong></p>
  
  <p><strong>Refused to set unsafe header "Connection"</strong></p>
  
  <p><strong>Even without the last 2 errors (if i dont set the connection,content-length headers) i will get the first error.</strong></p>
  
  <p>For my ajax functionality i am using this function:</p>
  
  <pre><code>function AjaxLoad(xhr, url, cfunc, syn, method, headers, params)
  {
      if (window.XMLHttpRequest) {
          xhr = new XMLHttpRequest();
      } else {
          xhr = new ActiveXObject("Microsoft.XMLHTTP");
      }
  
      xhr.onreadystatechange = cfunc; // This line take place on true/false
  
      xhr.open(method, url, syn);
      $.each(headers ,function(index, value){
          xhr.setRequestHeader(index, value);
      });
      xhr.send(params);
  }
  </code></pre>
  
  <p>At my js code i am calling the function like that:</p>
  
  <pre><code>var headersObject = {"Content-type" : "application/x-www-form-urlencoded", "Content-length" : userCap.val().length, "Connection" : "close" };    
  
  AjaxLoad(
      xhr,
      "../php/Ajax/captchaValidator.php",
      getResponse,
      false,
      "POST",
      headersObject,
      userCap.attr("name") + "=" + encodeURIComponent(userCap.val())
  );
  </code></pre>
  
  <p><strong>AjaxLoad arguments explanation:</strong></p>
  
  <ol>
  <li>xhr object</li>
  <li>location</li>
  <li>onreadystatechange handler</li>
  <li>Synchronous(its not working even if i will pass true)</li>
  <li>method</li>
  <li>headers</li>
  <li>key=value pair(I did test it so it get the right value)</li>
  </ol>
  
  <p><strong>This is the getResponse function:</strong></p>
  
  <blockquote>
  <pre><code>function getResponse(){
          var strongEl = capCon.next();
              if(xhr.responseText == "0"){
                  if(strongEl.prop("tagName") == "STRONG"){
                      strongEl.getReplace('&lt;strong id="sE"&gt;קוד שגוי&lt;/strong&gt;');
                  }else{
                      capCon.after('&lt;strong id="sE"&gt;קוד שגוי&lt;/strong&gt;').next();
                  }
                  bToSubmit = false;
              }else{
                  if(strongEl.prop("tagName") == "STRONG"){
                      strongEl.remove();
                  }
              }
      }
  </code></pre>
  </blockquote>
  
  <p>I test the network to see if the file <strong>captchaValidator.php</strong> is even get to the browser and i get status 200 everything seems ok.</p>
  
  <p>I did test for right values, The code did worked before i dont know what changed, But this is the link to my website registration page <a href="http://phpliteral.zapto.org/users/register.php" rel="nofollow">Link</a>, If you press <strong>send</strong>, You can see (in chrome browser at the network tab) that all is ok, But i get the errors i mentioned at the console tab, If some one can please take a look i will be very thankful.</p>