设置参数
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script type="text/javascript">
var jwt = '${jwt}';
//var returnUrl = '${returnUrl}';
var returnUrl = '/index.html';
setJwt(jwt);
window.location = returnUrl;
function setJwt(jwt) {
var store = window.localStorage;
if(store) {
store.jwt = jwt;
}
}
</script>
</head>
<body>
</body>
</html>
删除
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>微信示例</title>
<script src="https://cdn.bootcss.com/jquery/1.12.2/jquery.min.js"></script>
<style type="text/css">
body{font-size:80px;}
</style>
<script type="text/javascript">
var loginUrl = "/lego-web/weixinLogin.do";
function getJwt() {
var store = window.localStorage;
return store ? store.jwt : '';
}
function delJwt() {
var store = window.localStorage;
if(store) {
store.removeItem('jwt');
}
}
function postData() {
$.ajax({
type: 'POST',
url: '/lego-web/user/listUserAccount.do',
data: {},
headers: {
'Authorization': "Bearer " + getJwt(),
},
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(ret){
if(ret.code == 0) {
alert('成功')
console.log(ret)
}else if(ret.code == 401) { // 如果没有登录
alert('准备登录')
login('/lego-web/adminUser.html');
}
}
,error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
}
});
}
Vue.prototype.post = function(uri,param,success) {
this.$ajax({
url:url,
type:'POST',
data:JSON.stringify(param),
headers: {
'Authorization': "Bearer " + Vue.config.getJwt(),
'Content-Type' : 'application/json; charset=utf-8'
}
}).then(function(res){
console.log('res',res)
if(res && res.code == 401) {
alert('请求登录')
}else {
success(res)
}
}).catch(function(e){
alert(e)
});
}
var Action = {
ajax:function(uri,param,success) {
this.$ajax({
url:url,
type:'POST',
data:JSON.stringify(param),
headers: {
'Authorization': "Bearer " + VUE.config.getJwt(),
},
dataType: 'json',
contentType: "application/json; charset=utf-8"
}).then(function(res){
console.log('res',res)
success(res)
}).catch(function(){
})
}
}
function login(returnUrl) {
window.location = '/lego-web/api/weixinLogin.do?returnUrl=' + returnUrl;
}
function logout() {
delJwt();
login('/lego-web/adminUser.html');
}
</script>
</head>
<body>
<a href="#" onclick="logout()">重新登录</a> |
<a href="#" onclick="postData()">获取数据</a> |
<a href="pay/orderDetail.html">支付</a>
<div id="msg"></div>
</body>
</html>