zoukankan      html  css  js  c++  java
  • cookie记录

    登录页面引用:

    <script src="/jquery.cookie.js"></script>
    登录页面jq:
    var telphone = $('[name = "telphone"]').val();
    var pwd = $('[name = "pwd"]').val();
    //登录接口
    $.post("/sign",{
    login: telphone,
    password: pwd
    },function(data){
    if(data.status == 200){
    //登录成功后跳转到首页
    if(parame == 'index'){//从首页点击登录跳转到登录页面的索引
    //设置cookie
    $.cookie('login',telphone,{ expires: 365, path: '/index.html' });
    $.cookie('token',data.data.access_token,{ expires: 365, path: '/index.html' });
    $.cookie('username',data.data.username,{ expires: 365, path: '/index.html' });
    $.cookie('pwd',encrypt(pwd),{ expires: 365, path: '/index.html' }); //密码
    window.location.href = '/index.html?login='+telphone+'&access_token='+data.data.access_token+'&username='+data.data.username+'';
    }

    }
    else{
    alert(data.error);
    }
    })

    首页页面同样引用:
    <script src="/request.js"></script>
    <script src="/jquery.cookie.js"></script>
    首页jq:
    var login = request('login');

    var token = request('access_token');

    var username = request('username');

    var pwd;//加密密码
    //判断cookie中是否有登录的记录
    if($.cookie('login') == undefined || $.cookie('login') == ''){

    }else{
    login = $.cookie('login');
    }
    if($.cookie('token') == undefined || $.cookie('token') == ''){

    }else{
    token = $.cookie('token');
    }
    if($.cookie('username') == undefined || $.cookie('username') == ''){

    }else{
    username = $.cookie('username');
    }
    if($.cookie('pwd') == undefined || $.cookie('pwd') == ''){

    }else{
    pwd = $.cookie('pwd');
    }

    //首页点击退出登录
    $('.denglu').click(function(){
    $.cookie('login','',{ path: '/index.html' });
    $.cookie('token','',{ path: '/index.html' });
    $.cookie('username','',{ path: '/index.html' });
    $.cookie('pwd','',{ path: '/index.html' });
    window.location.href = '/index.html';

    /*清除所有cookie:
                      $.cookie('login','',{ path: '/' });
    $.cookie('token','',{ path: '/' });
    $.cookie('username','',{ path: '/' });
    $.cookie('pwd','',{ path: '/' });*/
    });


  • 相关阅读:
    手写一个call、apply、bind
    setTimeout
    meta标签及Keywords
    用VSCode插件来一键填满Github的绿色格子吧-AutoCommit
    前端工具-定制ESLint 插件以及了解ESLint的运行原理
    JS基础-全方面掌握继承
    JS基础-该如何理解原型、原型链?
    前端中等算法-无重复字符的最长子串
    前端面试 js 你有多了解call,apply,bind?
    博客图片失效?使用npm工具一次下载/替换所有失效的外链图片
  • 原文地址:https://www.cnblogs.com/mo-cha/p/6210513.html
Copyright © 2011-2022 走看看