[英]redirect to url does not work after ajax post
I'm trying to do the following: 我正在尝试执行以下操作:
Pass a variable to flask from ajax that is posted in an input field, and when flask gets it and inserts it into a mysql table, I'd like to redirect the url to a new page whose content is modified by the user entered text in the input field. 将变量从发布在输入字段中的ajax传递给flask,当flask获取它并将其插入到mysql表中时,我想将url重定向到一个新页面,该页面的内容由用户在输入字段。 The flask gets the variable (heheh) inserts it into mysql, so that works fine.
烧瓶获取变量(heheh)将其插入mysql,因此工作正常。
My problem is that the redirect does not happen, I get the following error: 我的问题是重定向不会发生,出现以下错误:
{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
What can be the problem? 可能是什么问题? Thanks
谢谢
$("#searcher").click(function(){
console.log('foo11');
$.ajax({
type: "POST",
url: "{{url_for('pubfd')}}",
data : JSON.stringify({'data': 'heheh'}),
contentType: "application/json", // this
dataType: "json",
success: function (msg) {
window.location.href = "http://43.234.32.9/index";
console.log('fo23o11');
},
error: function (jqXHR, textStatus, errormessage) {
console.log("-----ERROR: -----", errormessage);
console.log("-----ERROR2: -----", jqXHR);
console.log("-----ERROR3: -----", textStatus);
}
});
console.log('foo2');
});
I got ERROR3 : parseerror 我收到了ERROR3:parseerror
flask code: 烧瓶代码:
@app.route("/blic", methods=['GET', 'POST'])
def pubfd():
if request.method == "GET":
return render_template("fooldal.html")
clicked = "---"
if request.method == "POST":
clicked=request.json['data']
print("ez a clickedd", clicked)
return "ok"
通过删除dataType:“ json”,重定向有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.