Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

When using the jQuery submitHandler method, I'm posting the form data via ajax to the server. On success, another method is called that resizes a popup and notifies the user its all complete.

My problem is however, whilst posting the data, the form is getting validated again causing undesired effects.

My understanding is submitHandler shouldn't trigger the validation again?

submitHandler: function(form) {
    console.log('test');

In this instance, 'test' is being logged to the console, but the validation is being run once again (in this case, a server side validity check on an email address field).

I'm using a button type submit as the form element. Do I need to prevent defaults or something similar?

Your submitHandler should exist within the validate function. In addition you should call form.submit() yourself which will remove the recursive calls that would otherwise exist.

     $("#myForm").validate({
          submitHandler: function (form) {
              console.log('test');
              form.submit();
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.