【发布时间】:2021-01-28 02:44:42
【问题描述】:
我在前端使用 JS 从 python 烧瓶后端获取数据。
fetch("/get_masks", {
method : "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({"image_index" : 0})
}).then(response => response.json()).then( data => {
console.log(data["hello"]);
});
烧瓶:
@app.route("/get_masks", methods=["POST"])
def get_masks():
return jsonify(hello="test")
这很好用,但是如果我在响应中添加括号和分号,它就不再起作用了
.then(response => {response.json();}).then( data => {
console.log(data["hello"]);
然后“响应”返回一个未定义的对象。
有人知道为什么会这样吗?
提前谢谢你!
【问题讨论】:
-
你忘记了
return声明
标签: javascript flask promise fetch