common.js 714 B

123456789101112131415161718192021222324252627282930
  1. $(".btn-logout").click(function() {
  2. let token = getCookie('jwt_token');
  3. if(!token) {
  4. return
  5. }
  6. axios({
  7. method: 'post',
  8. url: 'https://www.choozmo.com:8887/logout_jwt',
  9. headers: {
  10. 'accept': 'application/json',
  11. 'Authorization': `Bearer ${token}`
  12. },
  13. data: ''
  14. }).then(res => {
  15. console.log(res.data);
  16. if(res.data.msg == 'ok'){
  17. document.cookie = 'jwt_token=null';
  18. }
  19. window.location.href = 'index.html';
  20. }).catch(err => {
  21. console.log(err);
  22. });
  23. });
  24. function getCookie(name) {
  25. const value = `; ${document.cookie}`;
  26. const parts = value.split(`; ${name}=`);
  27. if (parts.length === 2) return parts.pop().split(';').shift();
  28. }