html页面之间相互传值
常见的在页面登录过后会获得一个token值然后页面跳转时传给下一个页面
sessionStorage.setItem("token",result.token);//传输token
一班我们再建一个公共的文件来放置
var host = window.location.protocol + "//" + window.location.host;//获得页面ip和端口号
var token = "";
var t = sessionStorage.getItem("token");接收token
if (t != null) {
token = t;
}
别的页面
$.ajax({
type: "post",
url: host + "/dcms/api/v1/admin/login",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({
"account": accounts,
"passwd": passwd
}),
success: function (result) {
//console.log(result.token);
sessionStorage.setItem("token",result.token);//传值给下一个页面
if (result.adminType == 1) {
window.location.href = "logadmin/index.html";
}
if (result.adminType == 2) {
window.location.href = "systemadmin/index.html";
}
if (result.adminType == 3) {
window.location.href = "secadmin/index.html";
}
if (result.code != 0) {
//"账号或者密码错误,请检查后重新登录!"
$(".content").text(result.msg);
}
},
error: function (result) {
showGlobleTip("服务器异常,请联系管理员");
}
});