Dec-24-2018, 02:17 AM
(This post was last modified: Dec-24-2018, 02:17 AM by supernoobs.)
I have web login page using ajax call API process login, API was written by python flask.
Web login --> call API OK
API process database OK --> (it return data and status code 200 OK) but the web browser can get status code 200 (success)
Here my code: Jquery
Web login --> call API OK
API process database OK --> (it return data and status code 200 OK) but the web browser can get status code 200 (success)
Here my code: Jquery
$(function(){
$('#btn_login').click(function(){
var uname=$("#username").val();
var upass=$("#userpass").val();
$.ajax({
url: 'http://localhost:5000/login',
crossDomain: true,
data: {
username: uname,
password: upass,
},
type: 'GET',
success: function(response){
console.log(response);
alert("OK")
},
error: function(error){
console.log(error);
alert("Err");
}
});
});
});Here my python codeapp.route('/login', methods=['POST','GET'])
def login():
try:
conn = mysql.connect()
cursor = conn.cursor(pymysql.cursors.DictCursor)
if request.method=='POST':
_uname = request.form.get('username')
_upassword = request.form.get('password')
else:
_uname = request.args.get('username')
_upassword = request.args.get('password')
print("username:",_uname)
print("password:",_upassword)
if _uname and _upassword:
_hashed_password = _upassword
cursor.execute("select * from tbl_user where user_name=%s and user_pass=%s", (_uname,_hashed_password))
row = cursor.fetchone()
response_data = {
"result": row,
"sucess": True,
"status_code": 200,
}
return jsonify(response_data)
else:
return not_found()
except:
return not_found()
finally:
cursor.close()
conn.close()
