【发布时间】:2021-10-23 00:30:08
【问题描述】:
我正处于学习阶段,所以请多多包涵。我一直在尝试得到答案,但通常它的 type="POST" 从 JS 通过 AJAX 到 Flask。
这是我的 app.py。
@app.route("/dashboard", methods=["GET","POST"]);
def dashboard():
yearCount = #Sample list of dict data
return render_template("dashboard.html", yearCount=yearCount)
(编辑)如何从上面获取 yearCount 并通过 AJAX 将其传递给 javascript? yearCount 将在dashboard.html 呈现时加载。
这是我的 js
$.ajax({
url: '/dashboard',
type: "GET",
// data: "How do I get the data yearCount from /dashboard?",
success: function() {
alert(this.url);
}
});
非常感谢您的帮助!整整一周都在扯我的头发,试图寻找答案。
【问题讨论】:
标签: javascript python ajax variables flask