I'm sorry if this was asked before, but I need to send my form data with both the form and the ajax call, which fires when I submit. The reason is because the user is being redirected, and I want to save det formdata to my database in advance.
So, I'm trying to use the onsubmit and fire form of a javascript function that submits formdata. This does not work, the form is submitted and no ajax call is made. So I'm trying to get the ajax call out of the function and see if it works then, and this happens, when the page is refreshed, the ajax call is made and my database is updated.
Here is the som code:
HTML
<form id="danlevi" onsubmit="return senddata()" action='<?php echo esc_url( get_option( 'shopping_cart_url' ) ); ?>' method='post' enctype="multipart/form-data">
<input type="text" name="first" />
<input type="text" name="last" />
<input type="text" name="e-mail" />
<input type="text" name="phone" />
<input type="text" name="street" />
<input type="text" name="zip" />
<input type="submit" value="send" />
</form>
Javascript
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,
});
}
});
, , , , ajax, , .
return false, . , - , , , , . , , .