如何将列表从Python正确返回到Ajax,返回时输出看起来很奇怪
ap.py
@app.route('/_get_comUpdate/', methods=['POST'])
def _get_comUpdate():
comNr = request.form.get('comNr')
com_result = COMPort("ON","COM255",comNr)
print(com_result)
return jsonify({'data': render_template('com_response.html', com_result = com_result)})
com_response.html
{{com_result}}
index.html
$.ajax({
url: "/_get_comUpdate/",
type: "POST",
success: function(resp){
com_result = (resp.data);
alert(com_result);
}
});
python中列表的输出:
['ON', 'OFF', 'OFF', 'OFF', 'OFF', 'OFF']
返回到Ajax的列表的输出:
['ON', 'OFF', 'OFF', 'OFF', 'OFF', 'OFF']
很抱歉配方可能不准确,因为我看不到你所有的代码。我想原因在于指定了UTF-8编码
可能是后端
可能是前端
可以运行应用程序
还有,你能用json.dumps代替jsonify吗?希望对你有帮助)
相关问题 更多 >
编程相关推荐