javascript ajax post form data
$(document).ready(function() {
// process the form
$('form').submit(function(event) {
// get the form data
// there are many ways to get this data using jQuery (you can use the class or id also)
var formData = {
'name' : $('input[name=name]').val(),
'email' : $('input[name=email]').val(),
'superheroAlias' : $('input[name=superheroAlias]').val()
};
// process the form
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : 'process.php', // the url where we want to POST
data : formData, // our data object
dataType : 'json', // what type of data do we expect back from the server
encode : true
})
// using the done promise callback
.done(function(data) {
// log data to the console so we can see
console.log(data);
// here we will handle errors and validation messages
});
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
});
});
Also in JavaScript:
- clone node javascript
- split a message js
- make page refresh on top in react js
- chartjs min
- javascript parseint string with comma
- javascript break for loop
- route parammap subscribe angular 9
- How to add js file to a site through url
- remove all spaces from a string javascript
- how to show progress on ajax call
- select2 disable search
- $(getJson) returning error
- vue js Elements in iteration expect to have 'v-bind:key' directives
- string split last slash in js get previous results
- live background react
- error handling in node js
- promise all in promise all
- get element of an array inside another array
- empty string in javascript
- npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! functions@ lint: `tslint --project tsconfig.json`
- math random equitative js
- not equal to in js
- js remove the last character of a string
- what foreach method returns in javascript