How to bind to the submit event when HTML5 validation is used?

后端 未结 3 1365
情话喂你
情话喂你 2020-12-17 20:58

Using HTML5 validation...

In HTML5 browsers, validation occurs before the submit event. So if the form is invalid, the submit event never fires

3条回答
  •  天涯浪人
    2020-12-17 21:21

    if you want to use the browser default validation you should use the following as you need to bind to the default submit then prevent the it and use $.ajax or $.post

    $("form").bind('submit', function(e){
           e.preventDefault();
    
            $.post("url",$("form").serialize(),function(data){
                                 $("#result").html(data).show();
                                  });
           });
    

提交回复
热议问题