我试图简单地举下面的例子。基本上,我发现在常规页面请求(例如用于索引或/ login的请求)上,会话变量可用。但是对于从我的javascript方法进行的ajax调用,会话变量不可用。我的ajax函数使用fetch来调用/ ajax-call。这仅在边缘浏览器中发生。它适用于Chrome。想知道是否有人可以解决吗?
app.py
AddHandler Me.KeyDown, Sub(sender As Object, e As KeyEventArgs)
If e.Control AndAlso e.KeyCode = Keys.S Then
Dim bs As BindingSource = DirectCast(dgv.DataSource, BindingSource)
bs.RaiseListChangedEvents = False
dt.AcceptChanges()
bs.RaiseListChangedEvents = True
End If
End Sub
login.html
from flask import Flask
from flask import Flask, flash, redirect, render_template, request, session, abort
import os
app = Flask(__name__)
@app.route('/')
def home():
print('works all the time', session.get('username'))
return render_template('login.html')
@app.route('/ajax-call')
def ajax_call():
print('fails in edge',session['username'])
return 'data'
@app.route('/login', methods=['POST'])
def do_admin_login():
if request.form['password'] == 'password' and request.form['username'] == 'admin':
session['logged_in'] = True
session['username'] = 'goat'
else:
flash('wrong password!')
return home()
if __name__ == "__main__":
app.secret_key = os.urandom(12)
app.run(debug=True,host='0.0.0.0', port=4000)