我正在尝试编写代码,为页面请求数据,处理它,然后在页面的下半部分显示结果而不刷新。
Flask代码:
if request.method == 'GET':
return render_template("dashboard.html", data_nodes=data_nodes, data_para=data_para)
elif request.method=='POST':
#c, conn = connection2()
select1 = request.form.get('node')
select2 = request.form.get('parameter')
print str(select1)
print str(select2)
#processes the data
#display the processed data on the same page
#return render_template("dashboard.html") This will refresh the page! Is there another way?
我的HTML端
<form method="POST" action="{{ url_for('dashboard')}}">
<label for="node">Node</label>
<select name="node">
{% for o in data_nodes %}
<option value="{{ o.name }}">{{ o.name }}</option>
{% endfor %}
</select>
<label for="parameter">Parameter</label>
<select name="parameter">
{% for o in data_para %}
<option value="{{ o.name }}">{{ o.name }}</option>
{% endfor %}
</select>
<button type="submit" class="btn btn-default" >Send</button>
</form>
有没有办法发布处理过的数据而不必重定向到另一个页面?