我正在尝试使用Flask和HTML开发一个Web应用程序,现在我需要获取用户输入,将其传递给Python后端,执行一个函数并返回其输出,并将其放置在HTML元素内。我也希望在不刷新HTML页面的情况下发生这种情况。
我怎样才能做到这一点?在下面,我有到目前为止已经开发的代码,但是不能正常工作:
我的HTML:
我的Flask后端:
@app.route('/background_check_throughputrate', methods=['GET', 'POST'])
def background_check_throughputrate():
if request.method == 'POST':
text = request.form['throughput_rate_text']
processed_text = str(text)
throughput = transition_throughput_rate(processed_text)
return jsonify(throughput)
我的HTML(继续获取在Flask上执行的函数的输出):
$(function() {
$('a#checkThroughputRate').bind('click', function() {
$.getJSON('/background_check_throughputrate', function(data) {
console.log(dat