TL;DR for admins: Not a duplicate. I'm trying to force redirect the user from the Flask backend after completing survey using Flask, but it doesn't work (though from my understanding it should - it even behaves on console level as though as it did, but the browser doesn't reload). I do not want yet to do it on the ajax, I try to keep it as minimal as possible for now, the survey makes correctly a vanilla ajax POST to "/survey" and I want to keep it that way for now. Also, I want to understand the Flask problem instead of replacing it with another solution that I don't fully comprehend yet
I'm trying to learn some basics of Web development, wanting to make a somewhat interesting web app service using Flask as my backend.
My survey subsite of the project looks a little like this:
@app.route("/survey", methods=["GET", "POST"])
@login_required
def survey():
if request.method == "GET":
return render_template("survey.html")
if request.method == "POST":
x = request.get_json(silent=True)
print(x)
//todo: manipulate on x and classify a user into a group
return redirect(url_for("index")) // just for now redirect everybody
I'm a complete AJAX/JS newbie, but I know that my SurveyJS survey website ("/survey") after a bit of tinkering is sending the correct JSON to the backend (by printing the vast x variable after completion of the survey). Sadly, the redirects don't work, even though the server actually tries to do it - I have the standard 200 OK code in the console that I always got for the redirects on other subsides, but the website is not changed (no loading circle or anything). After the completion, I make a POST ajax request and the survey site gives the standard SurveyJS blank website with "Thank you for completing the survey!" (it doesn't load the website or anything)
Console Flask prompts:
INFO:werkzeug:127.0.0.1 - - [03/Jul/2017 20:06:44] "POST /survey HTTP/1.1" 302 -
INFO:werkzeug:127.0.0.1 - - [03/Jul/2017 20:06:45] "GET / HTTP/1.1" 200 -
What can I do to make the redirect work from the Flask level?