Python Forum
Flask return http status code 200 but web browser not recive
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask return http status code 200 but web browser not recive
#1
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
$(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 code
app.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()		
	
Reply
#2
I can't tell what your question is here.
Reply
#3
Maybe, you would like to edit your question. What do you think about it?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to Generate Class Code in Flask App - Form Not Submitting Correctly misbahskuy 1 1,215 Dec-08-2024, 07:07 PM
Last Post: snippsat
  help me in flask code iiiiiiiiii 1 1,092 Sep-03-2024, 06:53 AM
Last Post: ahmad_296
  PUT http query return <Response [500]> rndoma 7 8,844 Jun-10-2020, 09:17 PM
Last Post: rndoma
  problem with the return of flask loutsi 4 3,042 Jun-04-2020, 08:12 AM
Last Post: loutsi
  Return Frame as well as JSON response using same API in Flask Python Ask jenkins43 0 2,693 May-11-2020, 04:58 PM
Last Post: jenkins43
  [FLASK] How to structure the code in my case ? Fre3k 4 3,791 May-04-2020, 04:43 PM
Last Post: Fre3k
  Access Flask Web App from External Browser - IIS fioranosnake 3 3,381 Sep-16-2019, 06:22 PM
Last Post: ndc85430
  webdriver.remote to connect back existing browser without open new browser? gahhon 6 8,864 Feb-26-2019, 03:53 PM
Last Post: gahhon
  Flask: Error output to the browser instead of error_log nikos 1 3,519 Sep-28-2018, 12:49 PM
Last Post: thomasp
  Enable error logging to browser for Python's Flask under Apache + mod_wsgi nikos 1 3,961 Sep-18-2018, 09:15 PM
Last Post: nikos

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020