Please I am trying to simultaneously submit and validate my form to my database through the use of Ajax, but it is not working for me. Here is my jquery
$(document).ready(function(){
$(".button").click(function(){
$("#myform").validate();
//Ajax to process the form
$.ajax({
type: "POST",
url: "process.php",
data: { firstname: $("#firstname").val()},
success: function(){
$('#message').html(data);
}
});
return false;
});
});
The problem is when I submit the form,the Ajax form submit to itself. Please What is the right way to use the jquery validate and $.ajax together?
Pass
data
as a parameter in your success function:Your
success
function won't do anything because you haven't defineddata
Try this (working for me as expected):
HTML Form:
PHP Code:
First of all, why would you submit form if validation is not passed? Try this, if validate really validates:
You forget to pass the response