Guest User

Untitled

a guest
Jan 23rd, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <body>
  2. <input id="username"/>
  3. <input id="password" type="password"/>
  4. <button onclick="login()">login</button>
  5. <script>
  6. const username = document.getElementById("username");
  7. const password = document.getElementById("password");
  8. function login() {
  9. fetch("/api/login", {
  10. method: "post",
  11. headers: {
  12. "content-type": "application/json"
  13. },
  14. body: JSON.stringify({
  15. username: username.value,
  16. password: password.value
  17. }).then(function (response) {
  18. return response.json();
  19. }).then(function (result) {
  20. // TODO: show result to user
  21. }).catch(function (err) {
  22. // TODO: show error to user
  23. });
  24. });
  25. }
  26. </script>
  27. </body>
Add Comment
Please, Sign In to add comment