title: FormData Ajax not posting data in PHP
body: <p>Hope you can help me with my problem.</p>
  
  <p>The problem is that i put my <code>data</code> in <code>FormData</code> but when i'm calling them in php file using <code>echo</code> there is no values and data existing and gives me <code>error</code> </p>
  
  <blockquote>
    <p>an <code>undefined variable</code></p>
  </blockquote>
  
  <p>But when im using <code>var_dump()</code> or <code>print_r()</code> it show all the <code>values</code>. and also if i <code>var_dump</code> the files for the images it throws me also an <code>error</code>.</p>
  
  <p>Here in <code>html</code>:</p>
  
  <pre><code>&lt;form id="form" action="myurl.php" method="post" enctype="multipart/form-data" onsubmit="return false"&gt;
     &lt;input type="file" name="image" accept="image/*"/&gt;
     &lt;input type="text" name="description"/&gt;
     &lt;input type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is my code in <code>ajax</code>:</p>
  
  <pre><code> function getName(key)
   {
      key = document.getElementsByName(key)[0];
      return key;
   }
   function getId(key)
   {
      key = document.getElementById(key);
      return key;
   }
  
   var url = getId('form').getAttribute('action');
   var datas = new FormData();
   var xhr = new XMLHttpRequest();
  
   var image = getName('image').value.trim();
   var description = getName('description').value.trim();
  
   datas.append('file_image', image.files[0]);
   datas.append('description', description);
  
   xhr.open('POST', url, true);
   xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   xhr.send(datas);
  
   xhr.onreadystatechange = function()
   {
      var OK = 4;
      var DONE = 200;
  
      if(xhr.readyState == 4 &amp;&amp; xhr.status == DONE)
      {
         alert(xhr.responseText);
      }
   }
  </code></pre>
  
  <p>now in my <code>myurl.php</code> php file</p>
  
  <pre><code>var_dump($_POST);
  var_dump($_FILES);
  </code></pre>
  
  <p>We don't actually using third party <code>script</code> like <code>jQuery</code>. We practice native <code>javascript</code> language. </p>
  
  <p>Thank you.</p>