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: '/' });*/
    });


  • 相关阅读:
    oracle性能监控
    MySQL Explain详解
    oracle中merge into用法解析
    Mysql常见函数
    Quartz -第一篇-入门
    搭建zookeeper集群
    linux 安装mysql
    mysql无法远程访问
    ActiveMQ 持久化
    Nyoj 城市平乱(图论)
  • 原文地址:https://www.cnblogs.com/mo-cha/p/6210513.html
Copyright © 2011-2022 走看看