I have a JS function in my HTML template which is assigned to a button tap. When the user clicks the button I'm sending a POST
request to my Flask app which should make a redirect to another page. My problem is the redirection doesn't produce a real redirect, I mean my browser doesn't load the next page, while in the console I can see the 301
redirect on the network tab.
According to the browser's network tab, the redirection works, but my browser doesn't load the targeted url. This is how I manage the redirection with Flask:
@app.route("/signup/", methods = ['GET', 'POST'])
def signup():
if request.method == 'POST':
session['usess'] = request.json['usess']
#return redirect(url_for('index'))
return redirect("/", code=301)
if session:
return redirect("/", code=301)
else:
return render_template("signup.html")
# already tried simply
# return render_template("signup.html")
And this is what happens in the log of my Flask app:
127.0.0.1 - - [20/Dec/2017 15:01:33] "POST /signup/ HTTP/1.1" 301 -
127.0.0.1 - - [20/Dec/2017 15:01:33] "GET / HTTP/1.1" 200 -
Based on these logs it works, however my browser doesn't want to load the '/'
page.
And here is the function that is responsible for the session object. The whole process starts here:
btnSignUp.addEventListener('click', e => {
// ....
$.ajax({
type: "POST",
contentType: "application/json",
url: "/signup/",
data: JSON.stringify({usess: 'session_str'})
});
});
As the log shows the right requests I don't have an idea what can be the problem. I hope somebody with more experience can tell me what should I alter or try.