title: Form submit and Ajax at the same time using onsubmit?
body: <p>i am sorry if this have been asked before, but i need to send my form data with both the form submit and a ajax call that fires off when clicking submit. The reason why is because the user get's redirected and i want to store det formdata to my database beforehand.</p>
  
  <p>So i try to use the form onsubmit and fire of a javascript function that submits the formdata.
  This does not work, the form is sent and no ajax call is made. So i try to take the ajax call out of the function and see if it works then and it does, on page refresh the ajax call is made and my database updated.</p>
  
  <p>Here are som code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form id="danlevi" onsubmit="return senddata()" action='&lt;?php echo esc_url( get_option( 'shopping_cart_url' ) ); ?&gt;' method='post' enctype="multipart/form-data"&gt;
    &lt;input type="text" name="first" /&gt;
    &lt;input type="text" name="last" /&gt;
    &lt;input type="text" name="e-mail" /&gt;
    &lt;input type="text" name="phone" /&gt;
    &lt;input type="text" name="street" /&gt;
    &lt;input type="text" name="zip" /&gt;
    &lt;input type="submit" value="send" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>javaScript</strong></p>
  
  <pre><code>jQuery(document).ready(function() {
    function senddata() {
      var formdata = jQuery("#danlevi").serialize();
      var decoded = decodeURIComponent(formdata);
      strip = decoded.replace(/[\[\]]/g, "_");
      alert(strip);
      jQuery.ajax({
        type: "POST",
        url: 'dev/wp-content/themes/twentythirteen/custom/process_address.php',
        data: strip,
      });
    }
  });
  </code></pre>
  
  <p>I have no idea why this is not working, what i want is for the page to wait until the ajax call is made, when done, send the form as usual.</p>
  
  <p>If i use return false, it works. I hope that someone can explain what i obviously do wrong, and show me the way of doing this. The alert you see in this code is just for debugging.</p>