Advertisement
a123953

Untitled

Nov 24th, 2022
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function login(event) {
  2.     const json = {
  3.         email: event.email.value,
  4.         password: event.password.value
  5.     }
  6.     var xhr = new XMLHttpRequest();
  7.     xhr.open("POST", "http://192.168.149.145:8000/login", true);
  8.     xhr.setRequestHeader('Content-Type', 'application/json');
  9.     xhr.onreadystatechange = function () {
  10.         if (xhr.readyState == 4 && xhr.status == 200) {
  11.             alert("Successed");          
  12.             document.getElementById("formdata").reset();
  13.             // console.log(xhr.responseText);        
  14.             const res = JSON.parse(xhr.responseText);            
  15.             console.log(document.cookie);
  16.             localStorage.setItem("access_token",res.access_token);
  17.             localStorage.setItem("role",res.user.id);        
  18.         }
  19.     }
  20.     xhr.send(JSON.stringify(json));
  21.  // console.log(json);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement