ajax submit form script code example
Example 1: jQuery AJAX form submit
// jQuery ajax form submit example, runs when form is submitted
$("#myFormID").submit(function(e) {
e.preventDefault(); // prevent actual form submit
var form = $(this);
var url = form.attr('action'); //get submit url [replace url here if desired]
$.ajax({
type: "POST",
url: url,
data: form.serialize(), // serializes form input
success: function(data){
console.log(data);
}
});
});
Example 2: jquery ajax form submit example
$.ajax({
type: "POST",
url: "upload.php",
data: { name:name, mobile:mobile, address:address, city:city },
dataType: "json",
success: function(result){
}
});