app.py
@app.route('/cma/connect', methods=['GET', 'POST'])
def connect_management():
user = request.form.get('all_classes')
print('user:', user)
return str(user)
@app.route('/')
def index():
return render_template('app.html',
all_classes=default_classes)
app.html
<select name="selected_cma" class="form-control" id="all_classes">
{% for o in all_classes %}
<option value="{{ o }}" selected>{{ o }}</option>
{% endfor %}
</select>
</div>
<div class="form-group col-xs-3">
<label for="all_entries">the manager</label>
<button class="form-control" id="button" onclick="connect()">the reciever</button>
<p id="countdown"></p>
app.html中的js代码
$('#button').click( function(event) {
event.preventDefault();
$.post("/cma/connect", $('#form').serialize(), function(data) {
//alert(data);
countdown = $("#countdown");
countdown.append(data + "<br/>");
});
});
我的成绩
user: None
127.0.0.1 - - [19/Jun/2020 10:03:11] "POST /cma/connect HTTP/1.1" 200 -
我想要什么
user: (the selected option from the dropdown menu)
总结问题
我想将所选选项返回到我的flask api以供进一步使用,并显示它,而无需转到新的tab
有什么新方法吗
如果您不想在代码中使用
<form>
(这很奇怪),那么您可以尝试其余的应该是一样的
JavaScript
发送{"selected_cma": selected}
,因此Flask
必须在form.get('selected_cma')
中使用相同的名称及
并且不需要
onclick="onclick()"
,因为$('#button').click(...)
已经分配了函数。如果您有一些函数onclick()
,那么它可能会产生一些其他问题编辑:
最小工作代码
顺便说一句:上一个问题:how to access the selected dropdown back to flask
相关问题 更多 >
编程相关推荐