My app.route:
@app.route('/my_flask_route', methods=['POST'])
def receive_value():
data = request.get_json()
return jsonify(status="succes", data=data)
My JS:
document.addEventListener('DOMContentLoaded', function() {
fetch('/my_flask_route', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({}),
})
.then((response) => {
response.json().then((data) => {
console.log(data)
document.getElementById('input_value').value = data.my_dynamic_value;
})
.catch(error => console.error('Error fetching value:', error));
})})
I can see in the developer console that the value I’m looking for is stored as JSON:
{
"data": {
"my_dynamic_value": 5.1
},
"status": "succes"
}
I just seem to be stuck at passing the value to the JS script to overwrite a spin box in my html. All I see as a result is:
[Log] {data: {}, status: "succes"}