[英]redirect to url does not work after ajax post
我正在嘗試執行以下操作:
將變量從發布在輸入字段中的ajax傳遞給flask,當flask獲取它並將其插入到mysql表中時,我想將url重定向到一個新頁面,該頁面的內容由用戶在輸入字段。 燒瓶獲取變量(heheh)將其插入mysql,因此工作正常。
我的問題是重定向不會發生,出現以下錯誤:
{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
可能是什么問題? 謝謝
$("#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');
});
我收到了ERROR3:parseerror
燒瓶代碼:
@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.