Sending an Ajax request before form submit
$('form').submit(function(e) {
// this code prevents form from actually being submitted
e.preventDefault();
e.returnValue = false;
// some validation code here: if valid, add podkres1 class
if ($('input.podkres1').length > 0) {
// do nothing
} else {
var $form = $(this);
// this is the important part. you want to submit
// the form but only after the ajax call is completed
$.ajax({
type: 'post',
url: someUrl,
context: $form, // context will be "this" in your handlers
success: function() { // your success handler
},
error: function() { // your error handler
},
complete: function() {
// make sure that you are no longer handling the submit event; clear handler
this.off('submit');
// actually submit the form
this.submit();
}
});
}
});
Also in JavaScript:
- check if file exists javascript
- react enzyme simulate click sub component
- change the color of toast toastr js
- turn Iterator into array JS
- embed video by javascript
- javascript select2 sortable
- ejs
- Array Helpers
- how to write in js
- jquery on dom change
- intval js
- how to make an if statement in javascript
- swagger.json multiple file upload
- find object in array by property javascript
- does string contain special charactors javascript
- responsive grid using antd
- jquery count elements
- radio button group get value javascript
- vuejs pass all events to child
- jquery ajax post example
- javascript picture delete after time
- javascript rename keys in object
- javascript how to dynamically add asp button
- nodejs read file to array