0
我加了Cookie的會話來middleware.json 我想加上id登錄會話,並在功能addLead
回傳會話不保存
"session": {
"cookie-session": {
"params": {
"name": "id",
"secret": "secret",
"keys": [ "key1", "key2" ],
"httpOnly": "false"
}
}
}
登錄使用它:
router.post("/login", function (req, res)
{
req.session.id = req.body.id
req.sessionOptions.id = req.body.id
//...
})
addLead
router.post("/addLead", function (req, res)
{
console.log(req.session.id)
console.log(req.sessionOptions.id)
})
當addLead
我這叫,我得到
不確定
不確定
我測試使用的頁面:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"
integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s="
crossorigin="anonymous"></script>
<script>
function log(data)
{
console.log(JSON.stringify(data))
}
$.post("http://localhost:3000/login", { name: "John Smit", id: 15 }, function (data)
{
log(data)
$.post("http://localhost:3000/addLead", {
name: "Anton Berezin", phone: "337225", model: "1234",
mark: "Toyota", yearFrom: "2014", yearTo: "2017"
}, function (data)
{
log(data)
alert(JSON.stringify(data))
})
.fail(function (error)
{
log(error)
})
})
.fail(function(error)
{
alert(JSON.stringify(error))
})
</script>
</head>
<body>
</body>
</html>