jquery ajax常用的登录登出
整理jquery+ajax的登录登出方法。
//登录
var currentUserId = -1;
$(function() {
var timestamp = (new Date()).valueOf();
$.ajax({
type: 'POST',
url: '../m/user/getCurrentUser',
dataType: 'json',
data: {
t: timestamp
},
success: function(data) {
var isOK = false;
if(data.code == 1) {
var currentUser = data.object;
if(currentUser) {
$(".to_login").html('<a href="#">退出登录</a>');
$(".to_login").click(function() {
logout();
});
$(".wel_username").html("欢迎您,<span >" + currentUser.userName + "</span>");
currentUserId = currentUser.userId;
$(".get_username").html(currentUser.userName);
if(currentUser.userId != 1) {
$("#systemManage").hide();
}
if(currentUser.roleId == 3) {
isOK = true;
} else {
logout();
}
}
}
//登录失败
if(!isOK) {
window.location.href = "login.html";
}
}
});
});
//登出
function logout() {
$.ajax({
type: 'post',
url: '../m/user/logout',
dataType: 'json',
success: function(data) {
if(data.code == 1) {
window.location.href = "login.html";
}
}
})
}
//首页
$(document).ready(function() {
$('.to_login').click(function() {
$.cookie("autoLogin", 0);
$.cookie("password", "");
});
})
最新文章
- 【面试题】TB
- System.Threading.ThreadAbortException: 正在中止线程。
- java转义字符(转载)
- Java学习----日期函数
- css考核点整理(四)-css盒模型
- (导航控制器view)全屏幕滑动实现pop效果
- Js内存泄露问题总结
- dotnet的移除-->;安装 升级
- Python基础学习7---异常处理
- Javaweb阶段知识回顾一
- python自动安装mysql5.7
- Xen的虚拟化详解
- C++之标准库map
- Avalon MM 总线
- 正则表达式在python中的简单使用
- 平衡二叉树的java实现
- 好汉两个半第一季/全集Two And A Half Men迅雷下载
- 微信小程序之顶部固定和底部固定
- lua 工具类(一)
- EXPAT(XML解析库)