php – js countdown timer

Question:

Came here because I couldn't find a good answer on Google. There, when requesting a js timer, the devil will break his leg! In general, help find or share your timer. We need a timer in JS so that the time is set manually: 30 minutes, 1 day, 1 week and 1 month. (The timer should not restart after a page refresh). After the time is up, you need to use ajax to send a post request to the specified route (laravel) that the timer has ended.

Answer:

There are many countdown plugins for jQuery. For example https://github.com/kbwood/countdown allows you to do a countdown in any format – there are many examples .

The most popular countdown plugin is this one http://hilios.github.io/jQuery.countdown/lots of examples too.

jQuery(function($) {
  $('#countdown-example').countdown({
    until: new Date((new Date()).getFullYear() + 1, 1 - 1, 1),
    onExpiry: function(){ alert('Ура, новый год!!!'); /*Тут ваш POST запрос*/ },
    padZeroes: true
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/kbwood/countdown/master/dist/js/jquery.plugin.min.js"></script>
<script src="https://cdn.rawgit.com/kbwood/countdown/master/dist/js/jquery.countdown.min.js"></script>
<link href="https://cdn.rawgit.com/kbwood/countdown/master/dist/css/jquery.countdown.css">

<H2>Новый год скоро!</H2>
<span id="countdown-example"></span>
Scroll to Top