Graphs and tables for your Spotify account.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

  1. document.getElementById("login-btn").addEventListener("click", function() {
  2. let httpRequest = new XMLHttpRequest();
  3. /*
  4. * Handler for the response
  5. */
  6. httpRequest.onreadystatechange = function() {
  7. if (httpRequest.readyState === XMLHttpRequest.DONE) {
  8. if (httpRequest.status === 200) {
  9. // hide the login button
  10. document.getElementById('login').setAttribute("display", "none");
  11. let responseData = JSON.parse(httpRequest.responseText);
  12. let dataList = document.getElementById("data-list");
  13. for (let key in responseData) {
  14. let newLi = document.createElement("li");
  15. let innerList = document.createElement("ul");
  16. let dataLabel = document.createElement("li");
  17. dataLabel.innerText = key;
  18. let dataValue = document.createElement("li");
  19. dataValue.innerText = responseData[key];
  20. innerList.appendChild(dataLabel);
  21. innerList.appendChild(dataValue);
  22. newLi.appendChild(innerList);
  23. dataList.appendChild(newLi);
  24. }
  25. } else {
  26. alert("There was a problem with the login request, please try again!");
  27. }
  28. }
  29. }
  30. httpRequest.open('GET', '/login', true);
  31. httpRequest.send();
  32. });