cookie記錄

登陸頁面引用:html

<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: '/' });*/
});
相關文章
相關標籤/搜索