简体   繁体   English

为什么jquery表单没有在第一次点击时提交

[英]why jquery form not submitting on first click

I have one popup modal which submit to an ajax page after validation. 我有一个弹出模式,验证后提交到ajax页面。 Validation and submission are working perfectly. 验证和提交工作正常。 But the only issue, on first click it is not submitting the form or validation.On the second click it is working perfect. 但是唯一的问题是,第一次单击时并没有提交表单或验证,而在第二次单击时它运行良好。

Code: 码:

<script>
      $(function () {

        $('form').on('submit', function (e) {

          e.preventDefault();

          $('#gen-bar-form').validate({
                ignore: [],
                rules: { 
                        firstName: {
                            required: true
                        },
                        editor: {

                            required: true
                        }
                },

          submitHandler: function(form) {

             $("#loader-bg").css("visibility", "visible");

          $.ajax({
            type: 'post',
            url: 'action/file.php',
            data: $('form').serialize(),
            success: function (data) {
            var GenTokRet = JSON.parse(data);
            $("#gen-msg").html("<p>"+GenTokRet+"<p>");
            $("#loader-bg").css("visibility", "hidden");  

            }
          });

          }

          }); 

        });

      });
    </script>

You did wrong, because, you are using prevent default function for stopping the form , though jQuery validate will auto stop submitting form till it is valid. 您做错了,因为,尽管jQuery validate会自动停止提交表单,直到有效为止,您正在使用阻止默认功能来停止表单。 so just type validate function on submit function not needed 所以只需要在提交功能上键入验证功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM