I am using an ajax function to verify user login and i am returning json on errors . i wanted to redirect to a particular url on successive login, but the i can only send json data from my function (eliminating the possibility of using url_for or redirect ) . so How do i dynamically get the root url so i can send it via json and then redirect via javascript. heres my route`
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')
Thanks.
$.ajax({ type: "POST", url: pathname, data: data, success: function(data) { if(data.redirect) { window.location = data.redirectURL; } }in your ajax call and pass the redirectURL through flask. In flaskreturn jsonify(data=data)where data contains redirectURL etc