Last active
February 26, 2018 22:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gist 2 space indent not behaving