title: Send Form Data containing inputs and files with JQuery & AJAX to PHP Web Service
body: <p>I'm trying to send all data from my form with Jquery and Ajax to a PHP REST webservice. </p>
  
  <p><strong>JS</strong></p>
  
  <pre><code>$("#idform").submit(function(event) {
  
  /* Stop form from submitting normally */
  event.preventDefault();
  
  //Get Data
  var form = $(this),  
  formData = form.serialize(),
  formUrl = form.attr('action'),
  formMethod = form.attr('method');
  
  /* Send the data using post and put the results in a div */
  $.ajax({
      url: formUrl,
      type: formMethod,
      data: formData,
      dataType: "json",
      //processData: false,  // tell jQuery not to process the data
      //contentType: false   // tell jQuery not to set contentType
      success: function(res){
          if (res.result == '0') {
                  $("#idform").html('&lt;div class="text-lg"&gt;Good Job!&lt;/div&gt;');
              } else {
                  //$("#respuesta").html('Error:');
                  $("#respuesta").html(res.message);
              }     
      },
      error:function(res){
          $("#respuesta").html('Error comunicating webservice');
      }
  });
  </code></pre>
  
  <p>});</p>
  
  <p><strong>PHP</strong>
  I'm doing something like this with files:</p>
  
  <pre><code>if($_SERVER['REQUEST_METHOD'] == 'POST'){ 
  $fileuploaded = $_FILES['fileuploaded']['tmp_name'];
  $destinationpath = $_SERVER['DOCUMENT_ROOT']."/path/".$_FILES['fileuploaded']['name'];
  move_uploaded_file($fileuploaded, $destinationpath);}
  </code></pre>
  
  <p>Everythings go ok when I make POST from form directly to php file but not when I'm trying to send data with ajax. PHP web service recieves all inputs but no my two files :(</p>
  
  <p>Sorry for bad written english!</p>