I am new to AJAX.
I am trying to submit a form with ajax using the following logic:
//validate form
//if invalid never submit
//if valid, ajax request to get msg
//get success html if no server side errors exist. Replace sign up page with success html
//get fail message if server side errors exist, so the user can correct them (ex. invalid credit card no)
My AJAX:
$("form").submit(function(e){
if($(this).valid()) {
$.ajax({
url: 'formAction.php',
type: 'POST',
success: function(data){
/*convert php variables to JavaScript ones*/
if(success==true){
//relpace current page with confirmation
}
if(success==false){
//print out errors and allow user to re-submit
}
}
});
}
e.preventDefault;
});
I was wondering if I am on the right track with this implementation? or if this implementation is even possible?
I greatly appreciate any advice in making this implementation work.
Many thanks in advance!