ajax call php bootstrap validation

127

<form class="needs-validation" role="form" id="contact-form" method="post" novalidate>
        <input type="text" name="fullname" value="">
        <input type="email" name="email" value="">
<button type="button" id="submit">Send</button>
</form>
<script type="text/javascript">
  $(document).ready(function() {

$("#submit").click(function() {
    var form = $("#contact-form")

    if (form[0].checkValidity() === false) {
      event.preventDefault()
      event.stopPropagation()
    } else {
        var data = form.serialize();
        // console.log(data);
        $.ajax({
        type : 'POST',
        url  : '/submit.php',
        data : data,
        success :  function(data)
               {
                // console.log(data);
                    if(data.succ == 1)
                    {
                        console.log('Success');
                    }else{
                        console.log('Error');
                    }
               },
        error: function (data) {
                // console.log(data);
            }
        });
    }
    form.addClass('was-validated');

  });    
});
</script>

Comments

Submit
0 Comments