I am using html form and using php to submit this, but before submit I want to use ajax method for validation and checking response, if response true then return true else return false so till checking response html form should not get submitted but without checking response also form getting submit even I used return
<form method="POST" action="<?= base_url('save_details/')?>" onsubmit="return validate()">
<button type="submit">Add</button>
</form>
script
function validate(){
$.ajax({
type: "POST",
url: "<?= base_url('validate_email') ?>",
data: {
email: email,
},
dataType: 'json',
success: function (response)
{
if (response.status) {
return true;
} else {
return false;
// some message
}
}
});
}