title: Send FormData and String Data Together Through JQuery AJAX?
body: <p>How can I post file and input string data with <code>FormData()</code>? For instance, I have many other <strong>hidden input data</strong> that I need them to be sent to the server,</p>
  
  <p>html,</p>
  
  <pre><code>&lt;form action="image.php" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="file" name="file[]" multiple="" /&gt;
  &lt;input type="hidden" name="page_id" value="&lt;?php echo $page_id;?&gt;"/&gt;
  &lt;input type="hidden" name="category_id" value="&lt;?php echo $item_category-&gt;category_id;?&gt;"/&gt;
  &lt;input type="hidden" name="method" value="upload"/&gt;
  &lt;input type="hidden" name="required[category_id]" value="Category ID"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>With this code below I only manage to send the file data <strong>but not</strong> the hidden input data.</p>
  
  <p>jquery,</p>
  
  <pre><code>// HTML5 form data object.
  var fd = new FormData();
  
  var file_data = object.get(0).files[i];
  var other_data = $('form').serialize(); // page_id=&amp;category_id=15&amp;method=upload&amp;required%5Bcategory_id%5D=Category+ID
  
  fd.append("file", file_data);
  
  $.ajax({
      url: 'add.php',
      data: fd,
      contentType: false,
      processData: false,
      type: 'POST',
      success: function(data){
          alert(data);
      }
  });
  </code></pre>
  
  <p>server.php</p>
  
  <pre><code>print_r($_FILES);
  print_r($_POST);
  </code></pre>
  
  <p>result,</p>
  
  <pre><code>Array
  (
      [file] =&gt; Array
          (
              [name] =&gt; xxx.doc
              [type] =&gt; application/msword
              [tmp_name] =&gt; C:\wamp\tmp\php7C24.tmp
              [error] =&gt; 0
              [size] =&gt; 11776
          )
  
  )
  </code></pre>
  
  <p>I would like to get this as my result though,</p>
  
  <pre><code>Array
  (
      [file] =&gt; Array
          (
              [name] =&gt; xxx.doc
              [type] =&gt; application/msword
              [tmp_name] =&gt; C:\wamp\tmp\php7C24.tmp
              [error] =&gt; 0
              [size] =&gt; 11776
          )
  
  )
  
  Array
  (
      [page_id] =&gt; 1000
      [category_id] =&gt; 12
      [method] =&gt; upload
      ...
  )
  </code></pre>
  
  <p>Is it possible?</p>