I am working on python flask, I came across a problem. I want to send some specific data when I click on a button. I am attaching the codes below. All I want is inp data on start algo., other code flow is working fine.
function Started() {
var inp = "Started"
$.ajax({
url: "http://localhost:8080" + "/apis/algo/start",
type: "POST",
data: inp,
success: function(data) {
alert("Data submitted successfully....");
alert(JSON.stringify(inp));
},
error: function(data) {
alert("Error while submitting Data");
}
});
}
<button onClick="Started()">Start</button>
class StartAlgoAPI(MethodView):
def post(self):
Inp_data = request.form.get('inp')
print(Inp_data)
In Flask, you can use inp_data = request.get_json()
inside the function As you have not included @app.route
or similar in your excerpt, here is a link to a little tutorial you can find pretty quickly by using google https://techtutorialsx.com/2017/01/07/flask-parsing-json-data/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.