Reputation: 105
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. The flask gets the variable (heheh) inserts it into mysql, so that works fine.
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
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"
Upvotes: 0
Views: 244