Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. var btn = document.getElementById("useWish");
  2.  
  3.  
  4. function load () {
  5.  
  6.  
  7.  
  8. var xhr = new XMLHttpRequest();
  9. xhr.onreadystatechange = function() {
  10. if (this.readyState == 4 && this.status == 200) {
  11. var out = this.responseText;
  12. out = parseInt(out);
  13. out = Boolean(out);
  14.  
  15. console.log(out);
  16. if (out) { //make on
  17. btn.classList.add("musica-button-active");
  18. btn.innerHTML = "Aktiviert";
  19.  
  20.  
  21. }
  22. else { //make off
  23. btn.classList.remove("musica-button-active");
  24. btn.innerHTML = "Deaktiviert";
  25. }
  26.  
  27. btn.addEventListener("click", _=> {
  28. if (!btn.classList.contains("musica-button-active")) { //make on
  29. btn.classList.add("musica-button-active");
  30. btn.innerHTML = "Aktiviert";
  31.  
  32.  
  33. var xhr = new XMLHttpRequest();
  34. xhr.open("POST", "req.php?wish&useWish&Update=1", true);
  35. xhr.send();
  36.  
  37. }
  38. else { //make off
  39. btn.classList.remove("musica-button-active");
  40. btn.innerHTML = "Deaktiviert";
  41.  
  42.  
  43.  
  44. var xhr = new XMLHttpRequest();
  45. xhr.open("POST", "req.php?wish&useWish&Update=0", true);
  46. xhr.send();
  47.  
  48.  
  49. }
  50. });
  51.  
  52.  
  53. }
  54. };
  55. xhr.open("POST", "req.php?wish&useWish&Ask", true);
  56. xhr.send();
  57.  
  58.  
  59. };
  60.  
  61. load();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement