jwt javascript

[root@lnmp public]# cat jwt.html 
<!DOCTYPE html>
<html lang="en">
 
<head>
  <meta charset="UTF-8">
  <title>FormData</title>
</head>
 
<body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url:"http://192.168.2.131/api/auth/login",
dataType:'text',
data:"email=test115@163.com&password=115115",
success:function(data){
data = JSON.parse(data);
console.log(data);
$('#username').html(data.access_token);
$('#email').html(data.expires_in);
var storage=window.localStorage;
//写入a字段
storage["a"]=1;
//写入b字段
storage.b=1;
//写入c字段
storage.setItem("c",3);
storage.setItem("access_token",data.access_token);
}
});
})
</script>
hello.php
<span id=username></span> <span id=email></span>
</body>
</html> 
[root@lnmp public]# cat jwt1.html 
<!DOCTYPE html>
<html lang="en">
 
<head>
  <meta charset="UTF-8">
  <title>FormData</title>
</head>
 
<body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
var storage=window.localStorage;
access_token = storage.getItem("access_token");
alert(access_token);
let ajaxConfig = {
   host: 'http://192.168.2.131',
   authorization: 'Bearer '+access_token
}
$(document).ready(function(){
$.ajax({
type: "POST",
url:"http://192.168.2.131/api/auth/me",
dataType:'text',
data:{"sitename":"phpjx"},
headers: { "Authorization": ajaxConfig.authorization },
success:function(data){
data = JSON.parse(data);
console.log(data);
$('#username').html(data.name);
$('#email').html(data.email);
}
});
})
</script>
hello.php
<span id=username></span> <span id=email></span>
</body>
</html> 
[root@lnmp public]# 

    A+
发布日期:2019年01月18日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: