我正在尝试按下一个按钮,当单击它时,它应该发送一个发布请求并重定向到另一个网页
var url = '/hist_new/?' + url_back;
$.ajax({
context: this,
type: "POST",
url: url,
success: function(result) {
console.log("worked");
window.location.href = "http://localhost:3000/hist_new/";
}
});
/>
这是ajax请求,其中url_back是我创建的自定义查询字符串
@app.route("/hist_new/", methods=["POST", "GET"])
def hist2():
url_back = ""
if request.method == "POST":
url_back = request.url.split('?')[1]
print (url_back)
user_from_query = request.args.get("user", None)
selected_user = (
user_from_query if user_from_query is not None else request.cookies.get("ID", "")
)
username = request.cookies.get("username", "")
email = request.cookies.get("mdi_user_email", "")
args = dict(
template_name_or_list="tools/hist_frontend.html",
URL="http://localhost:3000"
+ "/hist_new/?user="
+ selected_user
+ "&username="
+ username
+ "&email="
+ email
+ url_back,
)
print (args)
return user_clearance(args, social_id=selected_user, coockies=request.cookies)
}
user_from_query,selected_user,username,email字段已经存在,并且是基于登录凭据的单独请求的一部分。我添加了url_back部分。
当前它正在打印正确的URL,但是当它重定向到该网页时,我相信该函数将再次被调用,因此该URL为空,仅包含用户,用户名和电子邮件字段。
有什么办法解决这个问题?