我当前的问题是我想在我的烧瓶网站上显示一个警报,该警报应该在我向烧瓶服务器发布请求后显示。
我已经尝试在JavaScript中进行一些提取。但是我不知道如何使它工作。
fetch('_get_message')
.then(response => response.json())
.then(data => {
alert(data);
console.log(data); // Prints result from `response.json()` in getRequest
})
.catch(error => console.error(error))
烧瓶服务器:
@app.route("/_get_message", methods=["POST", "GET"])
def get_message():
if request.method == "POST":
received_data = request.data.decode()
# check received json data
if received_data == None:
return "No data found in post", 400
print(received_data)
to_display = {"message": received_data}
return jsonify(to_display)
elif request.method == "GET":
return jsonify(to_display)
else:
return "Method not allowed", 305