how to send data from javascript to python flask
/* You can create a node.js web server and use Fetch/AJAX POST requests to send
data.
*/
/* Python Route Code */
@app.route('/postmethod', methods = ['POST'])
def get_post_javascript_data():
jsdata = request.form['javascript_data']
return json.loads(jsdata)[0]
/* Javascript Send Data */
fetch('Yourdomain.com/postmethod', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
'foo': 'bar'
}),
})
.then((res) => res.json())
.then((data) => {
// Do some stuff ...
})