title: How correctly pass data to php using ajax?
body: <p>I am trying to send FormData to a PHP file. When pressing submit nothing happens, but when I send data separately it does work.</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form method=&quot;post&quot; class=&quot;code_form&quot; enctype=&quot;multipart/form-data&quot;&gt;
    &lt;input id=&quot;my_file_id2&quot; class='upload_img' type=&quot;file&quot; name=&quot;my_file&quot;&gt;
    &lt;input id=&quot;code&quot; class='code' type=&quot;text&quot; name=&quot;my_text&quot;&gt;
    &lt;input type=&quot;submit&quot; id='fertig-btn' class='prime_sty' name=&quot;submit&quot;&gt;
  &lt;/form&gt;
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>$(&quot;.code_form&quot;).on(&quot;submit&quot;, function(e) {
    var formData = new FormData();
    
    if ($(&quot;.upload_img&quot;).val() != '') {
      file = $(&quot;.upload_img&quot;).prop('files')[0];
      formData.append(&quot;my_file&quot;, file);
    }
    
    var dota = $(&quot;.code&quot;).val();
    
    $.ajax({
      type: &quot;POST&quot;,
      url: &quot;img_proc.php&quot;,
      cache: false,
      contentType: false,
      processData: false,
      data: {
        formData,
        dota,
      },
      success: function(data) {
        $(&quot;.user-success-code&quot;).html(data);
      }
    })
  
    e.preventDefault();
  });
  </code></pre>
  <p>Sending data like this works:</p>
  <pre><code>data: formData,
  </code></pre>
  <p>Any idea how to solve it?</p>