Skip to content

Instantly share code, notes, and snippets.

@Cj1m
Created February 27, 2018 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cj1m/2812c0416e0a7a58439d9f02702648f5 to your computer and use it in GitHub Desktop.
Save Cj1m/2812c0416e0a7a58439d9f02702648f5 to your computer and use it in GitHub Desktop.
ajax post request
$('#swimmer-submit').on('click', function(e) {
e.preventDefault();
var values = {
swimmer : {
swimmer_forename: $('input[name="swimmer_forename"]').val(),
swimmer_surname: $('input[name="swimmer_surname"]').val(),
swimmer_dob: $('input[name="swimmer_dob"]').val(),
swimmer_gender: $('select[name="swimmer_gender"]').val(),
}
};
$.ajax({
url: "/addrecords",
type: "POST",
contentType: "application/json",
data: JSON.stringify(values),
success: function(response) {
if (response) {
console.log('Alerting success and clearing form');
alert("Success!");
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment