axios.post('', {data: params
},{headers: {'Access-Control-Allow-Origin':'*', //解决cors头问题'Access-Control-Allow-Credentials':'true', //解决session问题'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' //将表单数据传递转化为form-data类型},withCredentials : true
}).then(function (response) {var res = response.data;if(res=="登录成功,3秒后跳转主页") {var noticeId= JSON.parse(window.sessionStorage.getItem('user'));alert(noticeId)alert(response.data);setTimeout(that.LoginSuccess, 3000)}else if(response.data=="用户名不存在,请注册后重新登录") {that.message = response.data}}).catch(function (error) {alert(error);});
Flask
from flask import Flask, request,make_response,jsonify import json from flask_cors import CORS app = Flask(__name__) CORS(app, supports_credentials=True)