首页 > 代码库 > 登录成功返回登录前页面js代码
登录成功返回登录前页面js代码
/*------ setCookie(name,value) -----------*/
function setCookie(name,value)
{
var Days = 30; //此 cookie 将被保存 30 天
var exp = new Date();
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name + "="+ escape (value) + ";expires=" + exp + ";path=/";
}
/*-------- getCookie(name) ----------*/
function getCookie(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr !=null) return unescape(arr[2]); return null;
}
$(function(){
if($("#header")[0]){
setCookie("currentUrl", window.location.href);
}
})
调用
var currentUrl = getCookie(‘currentUrl‘);
setCookie("currentUrl", "");
$.ajax({
type: "post",
url: "/Ajax/User.ashx",
data: { "method": "Login", "username": $(".phoneNum").val(), "password": password, "Check_Pwd": $(‘#check‘).is(‘:checked‘) },
success: function (text) {
if (text == "error") {
$(".pwd").focus().tips({
bg:‘#1193f6‘,
msg: ‘用户名或密码错误~‘
});
}
else if (text == "error1") {
$(".phoneNum").focus().tips({
bg:‘#1193f6‘,
msg: ‘该用户已被禁用~‘
});
}
else if(text == "success") {
if (currentUrl != "" && currentUrl != null) {
window.location.href = http://www.mamicode.com/currentUrl;
} else {
window.location = ‘/index‘;
}
}
}
});
登录成功返回登录前页面js代码