I'm currently using an ajax function to validate user login credentials and returning JSON data in case of errors. However, I'm facing an issue where I need to redirect to a specific URL upon successful login, but I can only send JSON responses from my function which rules out the possibility of using url_for or redirect methods. So, how can I dynamically retrieve the root URL in order to include it in the JSON response and then perform the redirection using JavaScript?
def logincheck():
uname = request.form['username']
pwd = request.form['password']
if uname and pwd:
this = userlogin.query.filter_by(username = uname).first()
if this:
if this.password == pwd:
session['myid'] = this.uid
return jsonify(success = ?)
else:
return jsonify(p_error = 'Incorrect Password')
else:
return jsonify(u_error = 'Incorrect Username')
Thank you.