Creating a post from data returned from HTML form
I worked it out and re-wrote the code:
jQuery(document).ready(function() {
jQuery('#createacostume').submit(function( event ) {
event.preventDefault();
var aForm = jQuery(this);
var bForm = aForm.serializeArray();
bForm.push({name: 'action', value: 'myAjaxFunction'});
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: bForm,
success: function(resp) {
alert("Thank you for your post. We will review it and approve it shortly" + resp);
},
error: function( req, status, err ) {
alert( 'something went wrong, Status: ' + status + ' and error: ' + err );
}
})
.fail(function() {
alert("error");
})
;
return false;
});
});
You have to push onto the form the ajax function you are calling.