倒计时计时器在结束时重新启动

Countdown timer restart when it ends

我正在制作一个简单的倒计时脚本来更新我的用户,但是我希望脚本在计时器达到 0 时再次启动,此时计时器变为负数 -1、-2、-3 等..

HTML

<h5 id="update">Updating your profile in <span>10</span> seconds.</h5>

脚本

<script type="text/javascript">
    var sec = $('#update span').text()
    var timer = setInterval(function() {
        $('#update span').text(--sec);
        if (sec == 0) {
            $.ajax({
                url: "{{ url('/user/update') }}",
                type: "GET",
                data: { 'id' : {{ Auth::user()->id }} }
            });
        }
    }, 1000);
</script>

谢谢, 蒂亚戈

尝试这样的事情:

    var sec = $('#update span').text(), secInit = sec;
    var timer = setInterval(function() {
        $('#update span').text(--sec);
        if (sec == 0) {
            sec = secInit;
            $.ajax({
                url: "{{ url('/user/update') }}",
                type: "GET",
                data: { 'id' : {{ Auth::user()->id }} }
            });
        }
    }, 1000);