is that I have a form, and I need to avoid going through the submit if it does not meet certain conditions, this is my js.
$(document).on('click', '.validar', function (event) {
var parametros = {
"User": {
"username": $("#UserUsername").val()
}};
$.ajax({
url: '/Desarrollo/admin/users/validar',
data: parametros,
type: 'post',
dataType: "json",
success: function (response) {
if(response.error==true){
event.preventDefault();
}
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
}
});
});
If I put the event.preventdefault()
at the beginning ps does not go through the submit but if I just want to stop it if the field already exists.