问题
So I'm attempting to submit my form using ajax but I'm running into some issues where it's not submitting at all - Could someone explain to me what I might be doing wrong?
(function() {
'use strict'
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
const forms = document.getElementsByClassName('needs-validation')
// Loop over them and prevent submission
Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
}, false)
}());
<form class="needs-validation" id="contactForm" action="/" method="post" novalidate>
<h4 class="mt-5">Please provide your contact information</h4>
<div class="row mt-3">
<div class="col-md-4 mt-3">
<label for="firstName">First name</label>
<input type="text" class="form-control" id="firstName" name="contact[firstName]" required>
<div class="invalid-feedback">
First name is required.
</div>
</div>
</div>
<div class="row">
<div class="col-md">
<button class="btn btn-primary" type="submit">Submit Request</button>
</div>
</div>
</form>
来源:https://stackoverflow.com/questions/59549973/submit-form-using-ajax-using-bootstrap