I've been trying to figure out the best way to pass data from frontend to backend in Flask. The problem is that when receiving data on the back end, the data retrieval came from the request.form['msg'], which doesn't make sense since I didn't really use a form, just an input field. Why did it do this? Is there a better way to retrieve data?
Here's my code. There's also an index.html with <input id='msg'> </input>
jQuery / Javascript:
const message = document.getElementById('msg');
$(document).load('/run', {'msg': message.value}, function(){return 'run complete'})
main.py:
@app.route("/run", methods=["GET", "POST"])
def run():
if request.method == 'POST':
msg = request.form["msg"]
print('msg:', msg)
return "OK"