PHP not getting xmlhttprequest post
<p>I've been at this for hours and have yet to find a solution. Chrome's network activity shows that the post is being sent and the payload is "id=a1" but the php <strong>always returns an empty string</strong>. Either this is some silly typo that I've missed for the longest time, or my server host php.ini is blocking it. I contemplated the later, but I've used plenty of post scripts previously on this host without issue.</p>

<p>I've tried every combination I could think of with no avail :(</p>

<p>What could be causing this?</p>

<p>relevant .js:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var xhr;
if (window.XMLHttpRequest) {
  xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
  xhr = new ActiveXObject("Microsoft.XMLHTTP");
}

xhr.open("POST", "api.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www/form-urlencoded");
xhr.send("id=" + "a1");
xhr.onreadystatechange = display_data;

function display_data() {
  if (xhr.readyState == 4 &amp;&amp; xhr.status == 200) {
    alert(xhr.responseText);
  }

}</code></pre>
</div>
</div>
</p>

<p>relevant .php:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>$id = $_POST['id'];
echo $id;</code></pre>
</div>
</div>
</p>