james james - 1 year ago 137
Javascript Question

jQuery validate submitHandler triggers validation

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) {

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?

Answer Source

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.

      submitHandler: function (form) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download