title: how to use formData and closest functions together?
body: <p>I am using two jquery/ajax functions to submit data, for the pages with single forms and file upload in it I am using <code>var formData = new FormData(this);</code>.</p>
  <p>But I have multiple forms in some pages so I have to change function to <code>var form = $(this).closest('form');</code>.</p>
  <p>My question is : <strong>How can I use <code>closest();</code> function with formData in same function ?</strong>
  Then I can use same function for all pages instead using multiple functions.</p>
  <p>Here is my function can be used with multiple forms but doesnt post files.</p>
  <pre><code>$(document).ready(function() {
     $('.submit').on(&quot;click&quot;, function(e) {
      e.preventDefault();
        var form = $(this).closest('form');
      $.ajax({
        type:'POST',
        url:'../page',
        data:form.serialize(),
        success:function(vardata){
  
          var json = JSON.parse(vardata);
  
          if(json.status == 101){
           alert(json.msg);
           window.location.replace(&quot;/my-account/&quot;);
          } else {
            alert(json.msg);
            console.log(json.msg);
          }
        }
      });
    });
  });
  </code></pre>
  <p>And function with formData which is sending files but cant be used with multiple forms in same page.</p>
  <pre><code>  $(&quot;#ProForm&quot;).submit(function(e){
      e.preventDefault();    
      var formData = new FormData(this);
      $.ajax({
      url:'page.php',
      type: 'POST',
      data: formData,
      cache: false,
      contentType: false,
      processData: false,
        success: function(data) {
          var json = JSON.parse(data);
          if(json.status == 101){
            alert(json.msg);
            window.location.replace(&quot;/my-account/&quot;);
          } else {
            alert(json.msg);
            console.log(json.msg);
          }
        }
      });
    });
  </code></pre>
  <p>I tried this but didnt work <code>FormData(this).closest();</code> and <code>append();</code></p>