html ajax sessionid,HTML + AJAX + Python + Session?

I am trying to understand how to use AJAX with Python Sessions. I understand the basics of how sessions work. When I add AJAX to the mix, my mind is having a difficult time understanding the technical details. Part of me thinks AJAX and Python Sessoins are not possible. I know web frameworks exist that probably do all this magic but I want to learn how to do it myself before jumping into a framework.

I am trying to create a webpage with a login form using HTML, AJAX, Python, and Sessions. If the user is able to log in, a session should be created (I assume that's correct). Otherwise, an error message should be returned.

Here is the basic application layout:

login.html : HTML form with username & password input boxes and

submit button

ajax.js : contains AJAX function that communicates with server-side

script

check_user.py : checks if username & password are correct, creates

session or returns error

welcome.html : only accessible if username & password are correct

welcome_1.html : only accessible if username & password are correct

I prefer to keep the HTML, Javascript, and Python code in separate files as opposed to creating HTML with Python or using inline Javascript in HTML.

Here is the application logic:

user visits login.html

enters username & password

clicks submit button

submit button calls ajax function

ajax function sends username & password to check_user.py

check_user.py checks if username & password are correct

if not correct, return JSON formatted error message

else, correct

create session ID (SID)

place SID in cookie

return cookie to ajax function

redirect user to welcome.html

welcome.html

on page load, ajax function requests user's cookie

if no cookie, redirect to login.html

else, ajax function sends cookie to check_user.py

check_user.py opens cookie & verifies the SID

if not correct, redirect user to login.html

else, correct

redirect user to welcome.html

I think I am misunderstanding how ajax is supposed to handle the returned cookie information. It is also possible that I am misunderstanding other parts, too. Please clarify :-)

I think I will follow this document when writing my Python session code. Sound ok?

I am considering using jQuery for the AJAX stuff and other Javascript coding.

Thank you!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值