I have a form that I want to validate on both sides script and php. So I thought I can do an ajax request to a page to validate. After that if the validation is successful I want to go to the original page (the action of the form).
Is that possible?
I tried this code but its not working properly. Can someone help please?
$(document).ready(function () {
$('#checkout_form').on('submit', function (e) {
e.preventDefault();
var link = "{#$config.base_url_https}/function_ajax.php";
$.ajax({
url: link,
type: "POST",
data: $(this).serialize() + "&function_name=validate_checkout",
success: function (html) {
if (html == "false") {
location.href = "./login.php";
} else {
document.getElementById('checkout_form').submit();
}
},
error: function (jXHR, textStatus, errorThrown) {
// alert(errorThrown);
}
});
});
});
if its not possible is there any other way to do this?