how to send data from javascript to python flask

Solutions on MaxInterview for how to send data from javascript to python flask by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to send data from javascript to python flask"
Gaia
05 Jan 2020
1/* You can create a node.js web server and use Fetch/AJAX POST requests to send 
2data. 
3*/
4/* Python Route Code */
5@app.route('/postmethod', methods = ['POST'])
6def get_post_javascript_data():
7    jsdata = request.form['javascript_data']
8    return json.loads(jsdata)[0]
9/* Javascript Send Data */
10fetch('Yourdomain.com/postmethod', {
11  method: 'POST',
12  headers: { 'Content-Type': 'application/json' },
13  body: JSON.stringify({
14  	'foo': 'bar'
15  }),
16})
17  .then((res) => res.json())
18  .then((data) => {
19    // Do some stuff ...
20  })