【发布时间】:2019-10-18 12:27:30
【问题描述】:
当我点击生成时,我得到一个空的 []:
127.0.0.1 - - [18/Oct/2019 01:04:37] “POST / HTTP/1.1” 200 - []
这是 JS 中的数组和 JSON:
var List = [
{ load: "2", location: "3" },
{ load: "2", location: "4" },
{ load: "2", location: "8" },
];
document.querySelector('#generate').addEventListener('click',function() {
var json_list = JSON.stringify(List)
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "/",
traditional: "true",
data: json_list,
dataType: "json"
});
})
这是 Flask 中的代码:
@app.route('/',methods =['GET','POST'])
def index():
req = request.get_json()
print(req)
return render_template("index.html")
但是,如果我发送一个只有数字的数组,里面没有对象(例如 [2,3,4,5]),我实际上在我的 python 终端上得到了这个数组。那么我应该为要通过的对象添加什么?
编辑: 当我 jsonify 烧瓶中的输入时,我得到: Response 86 bytes [200 OK]
【问题讨论】:
标签: javascript arrays json ajax flask