How to call the ajax when form is valid
$('#form').validate({
... your validation rules come here,
submitHandler: function(form) {
$.ajax({
url: form.action,
type: form.method,
data: $(form).serialize(),
success: function(response) {
$('#answers').html(response);
}
});
}
});BY LOVE,
1- $("form").valid() is the main method which is checking the form is valid or not
2- 'btnsave' is the ID of the HTML BUTTON element.
3- Jquery pluggin should be added in this order
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
$('#btnSave').click(function () {
if ($("form").valid()) {
//alert('FORM VALID');
$.ajax({
url: 'http://localhost:3932/api/EmployeeService/Save',
type: 'POST',
dataType: 'json',
success: function () {
alert('Employee Save successfully');
},
error: function (xhr, textStatus, errorThrown) {
alert('Error occured');
}
});
}
});
Also in JavaScript:
- react native maps api key
- how to get the all input element id value using jquery
- decimal to base 32 javascript
- document.queryselector picks first or last
- most used events in javascript
- indexof javascript duplicate arrays
- multi-dimensional array js
- add 10px to width js
- js .length
- react native get location
- public class NameOf { public static String nameof<T>(Expression<Func<T>> name) { MemberExpression expressionBody = (MemberExpression)name.Body; return expressionBody.Member.Name; } }
- how to make use of nodejs single thread to read files and attach data
- javascript find the min in array of numbers
- get the last element of array javascript
- bootstrap 5 with angular modal
- cut string from string javascript
- foreach key value javascript
- indexof()
- how to setItem and getItem in javascript in localStorage
- cypress backspace
- react error boundary
- merge array in js
- js import and export
- jquery links