title: XMLHttpRequest not sending POST data
body: <p>I trying to send POST data to PHP file using XMLHttpRequest. The URL is right but PHP can't catch any of sent data and just back a null response.</p>
  <p>I'm using pure javascript from client and PHP 7.1 on server</p>
  <p>My PHP:</p>
  <pre><code>$data-&gt;msg = 'PHP is working';
  $data-&gt;user = $_POST['user'];
  $data-&gt;pass = $_POST['pass'];
  echo json_encode($data);
  </code></pre>
  <p>My Javascript:</p>
  <pre><code>var data = { 'user': 'myUser', 'pass': 'myPass' };
  
  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'myurl', true);
  xhr.setRequestHeader(&quot;Content-Type&quot;, &quot;application/json; charset=UTF-8&quot;);
  xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
          var res = JSON.parse(xhr.response);
          console.log(res);
      }
  };
  xhr.send(data);
  
  // Expected output: {msg: &quot;PHP is working&quot;, user: myUser, pass: myPass}
  
  // But just recive: {msg: &quot;PHP is working&quot;, user: null, pass: null}
  </code></pre>
  <p>I expect this response: {msg: &quot;PHP is working&quot;, user: myUser, pass: myPass}
  But just recive this: {msg: &quot;PHP is working&quot;, user: null, pass: null}</p>
  <p>As you can see PHP $_POST can't catch my sent post data and just back null. What's worng??</p>