title: Passing javascript object to php file using ajax post method
body: <p>Iam desperately trying to pass a json object using ajax post method to a php file, decode it and pass something back.
  Php's json_last_error displays 4, which means Syntax error.</p>
  
  <pre><code>this.send = function()
  {
      var json = {"name" : "Darth Vader"};
      xmlhttp=new XMLHttpRequest();
      xmlhttp.open("POST","php/config.php",true);
      xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
      xmlhttp.send("data="+json);
  
      xmlhttp.onreadystatechange=function()
      {
          if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
          {
              document.getElementById("result").innerHTML=xmlhttp.responseText;
              };
          }; 
      };
  
  
  &lt;?php   
  if(isset($_POST["data"]))
  {
      $data = $_POST["data"];
      $res = json_decode($data, true);
      echo $data["name"];
  }
  ?&gt;
  </code></pre>