1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //logout 放在routes/blog.js router.get( "/logout" , (req, res, next) => { //刪除session,同時在req.session中被移除,但是在下一次請求的時候又會被建立 req.session.destroy(); res.json( new SuccessModel()) }) --------------------------------------------------------------------- //html-test 登出 const $btnDel = $( "#logout" ) $btnDel.click( function () { get( "/api/blog/logout" ).then(res => { if (res.errno !== 0) { alert( '登出失败' ) return } alert( '登出成功' ) location.href = "/index.html" }) }) |