我正在使用 python flask
开发和应用程序,我想将 Javascript
函数(数组)的返回值发送到 python
函数 . 以下是代码 .
Javascript
<script>
function getVals(){
a = [ab, cd];
return a;
}
</script>
HTML
<a href="/end_stu_live_session">End This</a>
Python
@app.route('/end_stu_live_session')
def end_stu_live_session():
return render_template('stu_dashboard.html')
我希望将Javascript函数 getVals()
中的数组传递给python函数 end_stu_live_session
. 任何帮助都非常感谢 . 谢谢 .
1 回答
您可以通过Ajax将Javascript函数(数组)的返回值作为JSON发送到Python方法 .
从AJAX发送
contentType: 'application/json'
并在Flask中以request.json
接收数据 .app.py:
home.html:
Output: