When I click on the submit button, it still submits the form without validating the fields. I looked on other solutions here too, but no question mentions about what to do in the click function on submit.
Here's my code: https://jsfiddle.net/ishtiaq156/an1xqoxz/
Form:
$('#submitContact').click(function() {
var customerId = $('#customerId').val();
var formData = $('#addCustomerForm').serialize();
$.ajax({
url: "/abc/admin/customer/" + customerId + "/addContact",
type: "POST",
dataType: "json",
data: formData,
success: function(data) {
location.reload();
},
failure: function(errMsg) {
alert(errMsg);
}
});
});
JavaScript:
$('#submitContact').click(function() {
var customerId = $('#customerId').val();
var formData = $('#addCustomerForm').serialize();
$.ajax({
url: "/abc/admin/customer/" + customerId + "/addContact",
type: "POST",
dataType: "json",
data: formData,
success: function(data) {
location.reload();
},
failure: function(errMsg) {
alert(errMsg);
}
});
});