title: Pass Javascript variable to PHP
body: <p>I want to pass Javascript variable to PHP, but it is never set. I have everything in one .php file</p>
  
  <p>CODE:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" type="text/css" href="asd.css"&gt;
      &lt;title&gt;Tabulka&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;script&gt;
  $(document).ready(function(){
      $("#table tr").click(function(){
         $(this).addClass('selected').siblings().removeClass('selected'); 
  
         var value = $("#table tr.selected td:first").html();
  
          var xmlhttp = new XMLHttpRequest();
          xmlhttp.open("GET", "tabulka.php?id=" + value, true);
          xmlhttp.send();
      });
  });
  &lt;/script&gt;
  &lt;table id="table"&gt;  
      &lt;tr&gt;
          &lt;th&gt;A&lt;/th&gt; &lt;th&gt;A&lt;/th&gt; &lt;th&gt;B&lt;/th&gt; &lt;th&gt;C&lt;/th&gt; &lt;th&gt;D&lt;/th&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
          &lt;td&gt;51&lt;/td&gt; &lt;td&gt;41&lt;/td&gt; &lt;td&gt;1515&lt;/td&gt;  &lt;td&gt;419&lt;/td&gt;    &lt;td&gt;asd&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
          &lt;td&gt;52&lt;/td&gt; &lt;td&gt;41&lt;/td&gt; &lt;td&gt;1515&lt;/td&gt;  &lt;td&gt;419&lt;/td&gt;    &lt;td&gt;asd&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
          &lt;td&gt;63&lt;/td&gt; &lt;td&gt;41&lt;/td&gt; &lt;td&gt;1515&lt;/td&gt;  &lt;td&gt;419&lt;/td&gt;    &lt;td&gt;asd&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;form method="POST"&gt;
      &lt;input type="submit" name="ok-submit" class="ok" value="OKOK"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
  &lt;?php 
  if(isset($_REQUEST['id'])){
      echo $_REQUEST['id'];
  }
  ?&gt;
  </code></pre>
  
  <p>I am using XMLHttpRequest to pass variable. It works like If I click on table row. First td is pass to php variable and print it out the print it out. But he $_REQUEST['id'] is never set.</p>