JavaEar 专注于收集分享传播有价值的技术资料

Validation is not working with jqBootstrapValidation and ajax

In jQuery I am using $.ajax method with jqBootstrapValidation plugin on a bootstrap form but the validation is not working right. I am using


preventDefault is stopping validation from working but I don't want to actually submit the values so I am using event.preventDefault();. Any ideas?


  1. You just need to put the ajax function into the jqBootstrapValidation submitSuccess callback.

    You don't need to bind a trigger like "submit" or "click" on the form, because jqBootstrapValidation will handle the submit event.

    The following code is self-explanatory:

    $(function() {
        submitSuccess: function ($form, event) {
            type: 'POST',
            url: $form.attr('action'),
            data: $form.serialize(),
            success: function(data)
              // just to confirm ajax submission
              console.log('submitted successfully!');
          // will not trigger the default submission in favor of the ajax function

    For more details about the plugin:

  2. 参考答案2
  3. you must do something like below:

    $(function () { $("input,select,textarea").not("[type=submit]").jqBootstrapValidation({
        preventSubmit: false,
         submitSuccess: function (form, event) {
         submitError: function (form, event, errors) {
        }); } );