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


  • 相关阅读:
    打卡规则小模块设计
    json和ajax学习
    求两个数的百分比&时间格式化&ajax返回json
    spring security运行流程图(转)
    DelegatingFilterProxy作用浅析
    网站URL重写(Java UrlRewrite 的使用)
    JVM的常用的调优策略和垃圾回收算法及Tomcat的常用调优参数
    JQuery 的Ajax的使用
    servlet程序HTTP Status 500
    CanvasRenderingContext2D.drawImage()无效,not working
  • 原文地址:https://www.cnblogs.com/mo-cha/p/6210513.html
Copyright © 2011-2022 走看看