1// jQuery ajax form submit example, runs when form is submitted
2$("#myFormID").submit(function(e) {
3 e.preventDefault(); // prevent actual form submit
4 var form = $(this);
5 var url = form.attr('action'); //get submit url [replace url here if desired]
6 $.ajax({
7 type: "POST",
8 url: url,
9 data: form.serialize(), // serializes form input
10 success: function(data){
11 console.log(data);
12 }
13 });
14});
1$(function() {
2 $('form.my_form').submit(function(event) {
3 event.preventDefault(); // Prevent the form from submitting via the browser
4 var form = $(this);
5 $.ajax({
6 type: form.attr('method'),
7 url: form.attr('action'),
8 data: form.serialize()
9 }).done(function(data) {
10 // Optionally alert the user of success here...
11 }).fail(function(data) {
12 // Optionally alert the user of an error here...
13 });
14 });
15});
16
1$.ajax({
2 type: "POST",
3 url: "upload.php",
4 data: { name:name, mobile:mobile, address:address, city:city },
5 dataType: "json",
6 success: function(result){
7 }
8 });