ajax submit form data
$(function() {
$('form.my_form').submit(function(event) {
event.preventDefault(); // Prevent the form from submitting via the browser
var form = $(this);
$.ajax({
type: form.attr('method'),
url: form.attr('action'),
data: form.serialize()
}).done(function(data) {
// Optionally alert the user of success here...
}).fail(function(data) {
// Optionally alert the user of an error here...
});
});
});
<form id="contactForm1" action="/your_url" method="post">
<!-- Form input fields here (do not forget your name attributes). -->
</form>
<script type="text/javascript">
var frm = $('#contactForm1');
frm.submit(function (e) {
e.preventDefault();
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function (data) {
console.log('Submission was successful.');
console.log(data);
},
error: function (data) {
console.log('An error occurred.');
console.log(data);
},
});
});
</script>
Also in JavaScript:
- remove appended element jquery
- button click function in js
- addclass javascript
- check for internet explorer browser in javascript
- convert int to float in javascript
- javascript array remove first
- Aspect Ratio height react
- if media query jquery
- git remote url change
- if undefined angular
- accèder data-id javascript
- docker react module not found
- check array for duplicate values javascript
- tolowercase
- array.splice javascript
- strict equality operator
- discord.js command prompt notification
- jest Invariant Violation: could not find react-redux context value; please ensure the component is wrapped in a <Provider>
- angularjs 1.5.6 cdn
- strict equality
- react select with custom option
- what is code.jquery integrity crossorigin
- shuffle array javascript
- upload photos cypress