title: How to intercept auto submit form?
body: <p>My issue is I need to POST XML data to a payment gateway.</p>
  
  <p>I've tried to follow the answer from <a href="https://stackoverflow.com/questions/5576619/php-redirect-with-post-data">PHP Redirect with POST data</a>, but I need to intercept the submit to manipulate the data.</p>
  
  <p>So, I've tried the following:</p>
  
  <pre><code>&lt;html&gt;
  &lt;form id="myForm" action="&lt;?php echo $url; ?&gt;" method="post"&gt;
  
  &lt;/form&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready (function () {
      document.getElementById('myForm').submit();
  
      $('#myForm').submit(function (e) {
          console.log('A');
  
          e.preventDefault();
  
          alert("a");
  
          $.post("&lt;?php echo $url; ?&gt;", {'data': formxml}, function (data) {
              // callback logic
          });
      });
  });
  &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However, it doesn't work as I expected it to be.</p>
  
  <p>When I do the <code>document.getElementById('myForm').submit()</code>, I expected the <code>$('#myForm').submit</code> will intercept it and I can do data validation.</p>
  
  <p>How should I proceed with it in order to achieve my expected result?</p>