express前后端分离session的使用

express前后端分离session的使用
1、后端app.js中增加

app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "前端地址如:http://localhost:8080");
    //允许跨域后session的存取
    res.header('Access-Control-Allow-Credentials', "true");
    next();
});

2、前端,使用ajax()而不是getJSON()

    $.getJSON("");//无法加xhrFields:{withCredentials:true}
    $.ajax({
       usr: "",
       type: "",
       xhrFields:{
           withCredentials:true
       },
       success:function () {

       },
        error: function () {

        }
    });
原文地址:https://www.cnblogs.com/xiedong2016/p/11056566.html