Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. var firstTeam = -1;
  2. var secondTeam = -1;
  3.  
  4. $(document).ready(function () {
  5. $(".team").on("click", function () {
  6. firstTeam = parseInt($(this).data("index"));
  7. saving();
  8. });
  9. $(".team2").on("click", function () {
  10. secondTeam = parseInt($(this).data("index"));
  11. //saving();
  12. });
  13. $(".team").click(function (){
  14. var currentndex = parseInt($(this).data("index"));
  15. setColor1(currentndex);
  16. });
  17. $(".team2").click(function (){
  18. var currentndex = parseInt($(this).data("index"));
  19. setColor2(currentndex);
  20. });
  21. function setColor1(i){
  22. var z = i -1;
  23. $(".team:eq("+z+")").css("background-color", "#06523B");
  24. }
  25. function setColor2(i){
  26. var z = i- 1;
  27. $(".team2:eq("+z+")").css("background-color", "#06523B");
  28. }
  29. function saving(){
  30. var url = new URL(window.location.href);
  31. const apiUrl = "http://localhost:8000";
  32. $.ajax({
  33. url: apiUrl + "?page=comparison",
  34. method: "POST",
  35. dataType: "json",
  36. data: {
  37. rate: 1,
  38. firstTeam: firstTeam,
  39. secondTeam: secondTeam
  40. },
  41. success: function (result, textStatus, xhr) {
  42. console.log(xhr);
  43. if(xhr.status === 200){
  44. alert("Powinna wygrac "+ result);
  45. } else if(xhr.status === 201){
  46. alert("Brak mozliwosci sprawdzenia");
  47. }
  48. },
  49. error: function (err) {
  50. console.log(err);
  51. }
  52. });
  53. }
  54. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement