window.onload=function(){ $.post("/user/test.do", '', function(data, textStatus, req) { var json=null; console.log("登陆测试:"+data); try { json=JSON.parse(data); } catch (e) { // TODO: handle exception console.log(e); } if(json==null||json.code!=100){ var title; var content; var url; var reload=false; switch (json.code) { case 104: title="请登录"; content="还没登陆哦~"; url="/index.html" break; case 105: title="没有访问权限"; content="您无法访问当前页面"; url="home.html" reload=true; break; default: title="异常错误"; content="未知错误,请尝试重新登录"; url="/index.html" break; } var layer = layui.layer; layer.open({ title: title, content: content, cancel:function(index){ return false; }, btn: ['知道了'], btn1: function(data){ if(reload) window.history.go(-1); else window.location.replace(url); } }); }else{ console.log('登陆成功'); } }) $.post("/user/udata.do",function(data, textStatus, req){ var json=JSON.parse(data); $("#uname").text(json.uname); }) } function logout(){ $.post("/user/logout.do", function(data, textStatus, req) { var layer=layui.layer; layer.open({ title: "退出", content: "成功退出,欢迎下次光临", cancel:function(index){ return false; }, btn:['了解'], btn1:function(){ window.location.replace("/index.html"); } }) }); }