title: how can i send a variable to php file
body: <p>can someone show me how to send an variable to my php file out of that construct? i am new at ajax/javascript and i try to figure out my style for writing JS code. atm i like and understand that kind of version. </p>
  
  <pre><code>var ajax = new XMLHttpRequest();
  var method = "POST"
  var url = "data.php" //erweitern - später
  var asynchronous = true
  
  var button = document.getElementById("count")
  var counter = 0;
  button.onclick = function() {
      counter += 2;
      showMoreFood(counter)
  };
  ajax.open(method, url, asynchronous)
  ajax.send()
  ajax.onreadystatechange = function() {
      if (this.readyState == 4 &amp;&amp; this.status == 200) {
  
          var data = JSON.parse(this.responseText)
          var html =""
          //for (var a = 0; a &lt; data.length; a++) {
          for (var a = 0; a &lt; 2; a++) {
              var firstname = data[a].name
              var preis       = data[a].preis
  
              html += "&lt;tr&gt;"
              html +=     "&lt;td&gt;" + firstname  + "&lt;/td&gt;"
              html +=     "&lt;td&gt;" + preis          + "&lt;/td&gt;"
              html += "&lt;/tr&gt;"                     
          }
          document.getElementById("data").innerHTML = html
      } // if
  } // onready
  </code></pre>
  
  <p>what i tried:</p>
  
  <pre><code>var data = "variable1"
  ajax.open(method, url, asynchronous, data)
  
  in data.php
  -----------
  $variableA = $_POST['variable1'];
  </code></pre>
  
  <p>because i thought i could send the data within, but nope. thx and br </p>