How to store a JWT Token in a simple method and redirect to another page?

0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Title</title>
</head>
<body>
<form>
  <input type="email" name="email" placeholder="email">
  <button type="button" id="send">enviar</button>
</form>

<script
src="https://code.jquery.com/jquery-3.3.1.min.js"integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>

<script type="text/javascript">
  $('#send').on('click', function(){
    $.ajax({
      url: "URL QUE RETORNA O TOKEN",
      method: "post",
      contentType: "application/json",
      data: '{ "email": "[email protected]" }',
      success: function (data) {
        console.log(data);
     }
    });
  });
</script>
</body>
</html>

OBS: console.log (data); IT RETURNS TOKEN PERFECTLY

    
asked by anonymous 15.12.2018 / 04:12

1 answer

1

Store the return in a cookie:

localStorage.setItem("token", data);

and redirect:

location.href = "pagina.html";

On the redirected page, retrieve the value stored in the cookie:

localStorage.getItem("token");
    
15.12.2018 / 04:29