Skip to content

Instantly share code, notes, and snippets.

@Julian-Nash
Last active February 26, 2018 22:19
Show Gist options
  • Save Julian-Nash/5c985db03b49ca6f904f53ad5ae0e0a5 to your computer and use it in GitHub Desktop.
Save Julian-Nash/5c985db03b49ca6f904f53ad5ae0e0a5 to your computer and use it in GitHub Desktop.
Get form data on button click and make an ajax post to the server
// Submit form data to the server
$("#form_id").submit(function(e){
e.preventDefault();
// Create object to send to the server
var data = {
varOne: $("#input_id").val()
}
// ajax setup
var ajax_settings = {
url: "http://127.0.0.1:5000/example_endpoint",
data: JSON.stringify(data),
contentType: "application/json",
method: "POST",
dataType: "json",
success: function(resp){
// Do something on success
console.log(resp);
}
}
// Send it
$.ajax(ajax_settings);
@Julian-Nash
Copy link
Author

Gist 2 space indent not behaving

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment