【发布时间】:2021-08-31 05:17:51
【问题描述】:
我有一个方法尝试使用 GET 方法将变量传递给烧瓶。这是来自 jquery 和 flask 的代码:
const impacttoolbtn = document.querySelector(".changingtoolbtn")
impacttoolbtn.addEventListener("click", function (){
$.ajax({
url: "{{ url_for('impact') }}",
contentType: "application/json",
data: JSON.stringify(login_bool),
dataType: "json",
success: function(response) {
console.log(response);
},
error: function(err) {
console.log(err);
}
});
})
其中 login_bool 为真或假。
和烧瓶:
@application.route('/impact', methods=["GET"])
def impact():
data = request.get_json()
print(data)
print("hi")
return render_template('/impacttool.html')
我在打印(数据)上得到“无”,而如果我在 ajax 上而不是默认的 GET 上进行 POST,我会得到我需要的正确数据。为什么会发生这种情况?我很想得到一些见解,非常感谢。
【问题讨论】: