0
我想通過ajax後調用發送數組到燒瓶。但不知何故,它不工作。發送陣列從ajax到燒瓶不工作
的Javascript
<script type="text/javascript">
function fillChart()
{
var nids = document.getElementById("nodes-select").value;
var cfilter = document.getElementById("filter-select").value;
var chkd = document.getElementById("further-select");
var cids = [];
for (var i=0;i<chkd.length;i++)
{
if(chkd[i].selected)
{
cids.push(chkd[i].value);
}
}
alert(cids);
$.post("/pie",{"node_id":nids,"col_select":cfilter,"col_filter":cids},function(data,status)
{
var tmp = data;
console.log(data.otstr);
});
}
</script>
服務器代碼
@app.route('/pie',methods=['POST'])
def pie():
tmp1 = request.form.get('node_id')
tmp2 = request.form.get('col_select')
tmp3 = request.form.get('col_filter[]')
return jsonify(otstr=[tmp1,tmp2,tmp3])
這裏tmp1和TMP2僅僅是字符串和TMP3是strings.console.log(data.otstr)陣列是打印tmp1,tmp2的正確值,但是當涉及到tmp3時,它是一個數組,因此它僅打印第一個元素。
你嘗試'request.form.get( 'col_filter')' – Valijon
是。它使用console.log(data.otstr)打印它時給我空值 – krish
類似:[http://stackoverflow.com/a/24808706/3710490](http://stackoverflow.com/a/24808706/ 3710490) – Valijon