Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.23 KB | None | 0 0
  1. <button onclick="login()">Login</button>
  2. <div id="contenitore"></div>
  3.  
  4. <br><br><br>
  5.  
  6. <input type="text" id="token">
  7. <button onclick="list()">Lista Utenti</button>
  8. <div id="contenitorelista"></div>
  9.  
  10. <script>
  11. var login = function(){
  12.     var xhttp = new XMLHttpRequest();
  13.     xhttp.onreadystatechange = function() {
  14.         if (this.readyState == 4 && this.status == 200) {
  15.            // Typical action to be performed when the document is ready:
  16.            document.getElementById("contenitore").innerHTML = xhttp.responseText;
  17.                var par = JSON.parse(xhttp.responseText);
  18.                if(par.status){
  19.                    document.getElementById("token").value = par.token;
  20.                }
  21.         }
  22.     };
  23.     xhttp.open("GET", "/login", true);
  24.     xhttp.send();
  25. }
  26.  
  27. var list = function(){
  28.     var xhttp = new XMLHttpRequest();
  29.     //setto token nell'header
  30.     xhttp.setRequestHeader("token", document.getElementById("token").value);
  31.     xhttp.onreadystatechange = function() {
  32.         if (this.readyState == 4 && this.status == 200) {
  33.            // Typical action to be performed when the document is ready:
  34.            document.getElementById("contenitorelista").innerHTML = xhttp.responseText;
  35.         }
  36.     };
  37.     xhttp.open("GET", "/listautenti", true);
  38.     xhttp.send();
  39.        
  40. }
  41. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement