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
  PUT http query return <Response [500]> rndoma 7 4,428 Jun-10-2020, 09:17 PM
Last Post: rndoma
  problem with the return of flask loutsi 4 2,096 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 1,862 May-11-2020, 04:58 PM
Last Post: jenkins43
  [FLASK] How to structure the code in my case ? Fre3k 4 2,642 May-04-2020, 04:43 PM
Last Post: Fre3k
  Access Flask Web App from External Browser - IIS fioranosnake 3 2,386 Sep-16-2019, 06:22 PM
Last Post: ndc85430
  webdriver.remote to connect back existing browser without open new browser? gahhon 6 6,754 Feb-26-2019, 03:53 PM
Last Post: gahhon
  Flask: Error output to the browser instead of error_log nikos 1 2,760 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,053 Sep-18-2018, 09:15 PM
Last Post: nikos
  python3 + Flask + SQLite = HTTP 400 supertoy 5 5,599 Jan-30-2018, 02:13 PM
Last Post: supertoy
  starting with flask: code does not work Peter_EU 2 3,408 Oct-20-2017, 05:35 PM
Last Post: Peter_EU

Forum Jump:

User Panel Messages

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