Add e.preventDefault() to the else statement.
If you look at # 227 in the source code , the validator will prevent the form from being submitted if the form is invalid. Therefore, e.isDefaultPrevented() can be used to check if the form is invalid.
The form action is executed by default if the form is valid, which submits the form (why reloading the page). Since you need to do ajax, you have to stop the default action on e.preventDefault()
$('#send-form').validator().on('submit', function (e) { if (e.isDefaultPrevented()) { alert('form is not valid'); } else { e.preventDefault(); alert('form is valid');
Here is the demon
Hope this helps
source share