jQuery validation: some of the required field not filled but the form can still be submitted

前端 未结 3 1301
挽巷
挽巷 2021-01-26 01:18

I used jquery validation (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) for form validation. The followings are some fragments of my code:

HTML:

<
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-26 01:58

    Summing up, in order to employ both form validation and ajax submission, add 'submitHandler' to the validate() function:

    $("#formID").validate({
      onkeyup:false,
    
      rules: {
        ...
      },
    
      messages: {
        ...
      },
    
      // Submit the form
      submitHandler: function(form) {
        theUrl = '/processData';
        var params = $(form).serialize();
        $.ajax ({
          type: "POST",
          url: theUrl,
          data: params,
          processData: false,
          async: false,
          success: function(returnData) {
            $('#content').html(returnData);
          }
        });
      }
    
    });
    

提交回复
热议问题