tegarkurniawan

time cooldown

Jul 28th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. var interval = setInterval(function() {
  2. $.ajax({
  3. url: "conf/checktime.php",
  4. type: 'GET',
  5. data: '',
  6. async: false,
  7. dataType: "json",
  8. success: function (data) {
  9. console.log(data);
  10. var timer2 = localStorage.getItem('timer');
  11. if(data.status == 'Ada'){
  12.  
  13. if(timer2 === null) timer2 = "02:00";
  14. $('.countdown').html(timer2);
  15.  
  16. var interval = setInterval(function() {
  17.  
  18. var timer = timer2.split(':');
  19. var minutes = parseInt(timer[0], 10);
  20. var seconds = parseInt(timer[1], 10);
  21. --seconds;
  22. minutes = (seconds < 0) ? --minutes : minutes;
  23. if (minutes < 0){
  24. clearInterval(interval);
  25. localStorage.removeItem('timer');
  26. $('.countdown').html('');
  27. $.ajax({
  28. url: "conf/checktimeupdate.php",
  29. type: 'GET',
  30. data: '',
  31. async: false,
  32. dataType: "json",
  33. success: function (data) {
  34.  
  35. },
  36. cache: false,
  37. contentType: false,
  38. });
  39. }else{
  40. seconds = (seconds < 0) ? 59 : seconds;
  41. seconds = (seconds < 10) ? '0' + seconds : seconds;
  42. $('.countdown').html(minutes + ':' + seconds);
  43. timer2 = minutes + ':' + seconds;
  44. localStorage.setItem('timer',timer2);
  45. }
  46.  
  47. }, 1000);
  48. }else if(data.status == 'Tidak'){
  49. console.log("B");
  50. // clearInterval(interval);
  51.  
  52. $('.countdown').html('');
  53. localStorage.removeItem('timer');
  54.  
  55. }
  56. },
  57. cache: false,
  58. contentType: false,
  59. });
  60. }, 1000);
Advertisement
Add Comment
Please, Sign In to add comment