In my code's else condition I want to remove preventDefault() and submit the form.
I don't know to do this?
if(email.val() != ""){
//check email
e.preventDefault();
$.ajax({
type: 'post',
url: '/register/check-email',
data: {email: email.val()},
success: (data) => {
console.log(data);
if(data == 1){
name.css('border', '1px solid #248ea9');
email.css('border', '1px solid red');
$("div.wrapper div.right div.form form small.error-name").hide();
$("div.wrapper div.right div.form form small.error-email").hide();
$("div.wrapper div.right div.form form small.error-email-found").show();
}else{
//remove preventDefault()
}
}
})
}
preventDefault()will not run in theelseblock since you haven't put it in there. Or rather, none of the code in the first set of{ }will run if yourelseblock of code fires. It's one or the other. You can't remove something thats not there to begin with.$.ajax()is an asynchronous task, but why should it not be possible to submit the form in theelsebranch?thisshould be the form, hencethis.submit()would also work, hence no need to query the DOM again and no additional jQuery object.