title: get POSTed JSON Array in php
body: <p>How can I send a <code>POST</code> request along with a <code>JSON</code> array to <code>main.php</code> to return the value of <code>key_1</code>? My current method below doesn't work and I can't figure out how to fix this.</p>
  
  <p><code>script.js:</code></p>
  
  <pre><code>var array = {};
  array["key_1"] = "obj_1";
  array["key_2"] = "obj_2";
  array["key_3"] = "obj_3";
  
  var http = new XMLHttpRequest();
  http.open("POST", "main.php");
  http.onload = function () {
      document.querySelector("p").innerHTML = this.responseText;
  }
  http.send(array);
  </code></pre>
  
  <p><code>main.php:</code></p>
  
  <pre><code>&lt;?php
      $params = json_decode(file_get_contents("php://input"));
      echo ($params["key_1"]);
  ?&gt;
  </code></pre>
  
  <p><code>index.html:</code></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;p&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>