title: POST JSON data and a file to PHP backend
body: <p>I've built this custom form where users can click on buttons to configure their own product. This data is then sent with AJAX to my PHP backend (Wordpress) where it is processed and stored in the database. I'd like to allow users to upload files as well, but how can I send this file and the JSON data I have right now with the same POST request to the backend?</p>
  
  <p>configurationData is an array that stores the selected components. detailsFormData contains name, email etc. in the same format.</p>
  
  <p>Javascript that handles the AJAX request:</p>
  
  <pre><code>$.post(
      stac.ajax_url, {
        'action': 'add_configuration',
        'nonce': stac.nonce,
        'configurationData': configurationData,
        'detailsFormData': detailsFormData,
      },
      function( response ) {
        if( response.success ) {
          // do some fancy things
        } else {
          // more stuff
        }
      }
    );
  </code></pre>
  
  <p>This works fine, but obviously it doesn't let users upload a file yet. I've tried a bunch of tutorials but those only allow a file upload and nothing else, so no json data. Also tried some stuff with <code>var formData = new FormData(this);</code> and adding some settings (<code>processData: false</code>, <code>contentType: false</code> and <code>cache: false</code>), but that posts a single javascript object and I'm not sure how to handle that in the backend.</p>
  
  <p>EDIT: I've seen the links, but they do not explain how I can add this to the data that's being sent:
  <code>'action': 'add_configuration',
  'nonce': stac.nonce,
  'configurationData': configurationData,
  'detailsFormData': detailsFormData,</code></p>
  
  <p>EDIT2: Can just append these in the same way that formData is appended. Should work now, haven't handled it in the backend yet though.</p>