title: Ajax post form auto submit on load
body: <p>I'm trying to post a form to a database using ajax. I have tested the form and the php which all work when I manually submit. But the issue I have is when I try to auto-submit on page load using ajax it just doesn't seem to fire.</p>
  
  <p>I don't get any console errors and the form does get removed. It is just the ajax that doesn't kick in.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>setTimeout(function() {
    $("form.display-hide").submit(function(e) {
      e.preventDefault();
      $.ajax({
        url: '//www.mysite.com/inc/page-trustpilot.php',
        type: "POST",
        data: $(this).serialize(),
        success: function() {
          alert('hello');
        }
      }); // AJAX Get Jquery statment
  
    });
    $("form.display-hide").remove();
  }, 2000);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form class="display-hide" method="post"&gt;
    &lt;input class="totaltrsut" type="text" value="" name="totaltrsut"&gt;
    &lt;input class="totalreviews" type="number" value="" name="totalreviews"&gt;
    &lt;input type="hidden" name="token" value="&lt;?php echo $newToken; ?&gt;"&gt;
    &lt;input class="committodb" type="submit" value="Add Stats"&gt;
  &lt;/form&gt;
  
  &lt;?php
   if (!empty($_POST)) {
   global $wpdb;
  
   $successa=$wpdb-&gt;update( '6H921_dc_additional', array( 'addi_value' =&gt; $_POST['totaltrsut'] ), array( 'addi_id' =&gt; 1 ), array( '%s', '%d' ), array( '%d' ) );
   $successb=$wpdb-&gt;update( '6H921_dc_additional', array( 'addi_value' =&gt; $_POST['totalreviews'] ), array( 'addi_id' =&gt; 2 ), array( '%s', '%d' ), array( '%d' ) );
  if($successa &amp;&amp; $successb){
   //echo 'data has been saved'; 
  } else {
   //echo 'data has not been saved'; 
   }
   }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>