title: XMLHttpRequest POST method to PHP server receives no POST params but GET fine
body: <p>I am a newbie attempting to use XMLHttpRequest. I have studied numerous examples scattered across the Internet. I have no problems using the GET method, but when I tried switching to POST it fails to transfer the parameters. :(</p>
  
  <p>Here is my stripped down example which replicates the problem:</p>
  
  <p>Javascript:</p>
  
  <pre><code>function GetPostTest(url)
  {
    var req       = null;
    var postParms = 'p1=x&amp;p2=y';
    var getParms  = '';
    getParms = 'g1=a&amp;g2=b';
    if ( getParms )  url += '?'+getParms;
    req = new XMLHttpRequest
    if ( req )
    {
      req.open( 'POST', url, true );
      req.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
      req.setRequestHeader( "Content-length", postParms.length );
      req.setRequestHeader( "Connection", "close" );
      req.onreadystatechange = function()
      {
        if ( req.readyState == 4 &amp;&amp; req.status == 200 )
        {
          alert( 'Got Stuff Back: ' + req.responseText );
        }
      }
      req.send( postParms );
    }
  }
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>&lt;?php
  foreach ( $_POST as $key=&gt;$value )      echo htmlspecialchars(' _POST['.$key.']=['.$value.']');
  foreach ( $_GET as $key=&gt;$value )       echo htmlspecialchars(' _GET['.$key.']=['.$value.']');
  foreach ( $_REQUEST as $key=&gt;$value )   echo htmlspecialchars(' _REQUEST['.$key.']=['.$value.']');
  exit;
  ?&gt;
  </code></pre>
  
  <p>In this example, the server just reports back all of the GET and POST parameters it received which are then shown in the alert box.  I have thrown a couple of GET parameters in there also.  The parameters I pass are:</p>
  
  <ul>
  <li>GET:  g1=a&amp;g2=b</li>
  <li>PUT:  p1=x&amp;p2=y</li>
  </ul>
  
  <p>The alert box shows: "Got Stuff Back: _GET[g1]=[a] _GET[g2]=[b] _REQUEST[g1]=[a] _REQUEST[g2]=[b]".  This tells me that it is sending to the server okay, and coming back okay, just that the POST variables are not coming through.</p>
  
  <p>I turn off the getParms so I only send POST parameters and then I see no variables.  I turn off any combination of the three setRequestHeader()'s or other variations I see in sample code, and it does not change anything.</p>
  
  <p>I am testing with Google Chromium Version 24.0.1312.56 Ubuntu 11.10 (24.0.1312.56-0ubuntu0.11.10.1) and Apache on Xubuntu 2.2.20-1ubuntu1.3 with PHP.</p>
  
  <p>Thanks for your analysis.  What does it take to fix this to push the POST parameters through?</p>