How to onlick call ajax and After Start count Down Does not chnage on refresh Page in Php

AJAX / November 28, 2021 / by nwebsolution
<a href="javascript:void(0);" id="priceatag" title="Price account" 
onclick="pricecsvgenerate('<?php echo $AccId;?>');">
<button type="button" id="pricesysc" class="btn btn-default btn-circle">
<i class="fas fa-sync"></i></button><span class="countdown"></span></a>
                     
<div id="demo"></div>
<script>
function calltimer()
{
    if( typeof sessionStorage.loginData === 'undefined')
    {
        $('#pricesysc').removeAttr("disabled");
        $("#priceatag").css({"pointer-events": ""});
    }
    else
    {
    $('#pricesysc').attr("disabled", true);
    $("#priceatag").css({"pointer-events": "none"});
    console.log(sessionStorage.loginData);
    var countDownDate = new Date(sessionStorage.loginData).getTime();

    var x = setInterval(function() {
    // $('#pricesysc').attr("disabled", true);
    var now = new Date().getTime();

    var distance = countDownDate - now;

    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);

    // Output the result in an element with id="demo"
    document.getElementById("demo").innerHTML =  minutes + "m " + seconds + "s ";
    // If the count down is over, write some text 
    if (distance < 0) 
    {
        clearInterval(x);
        $('#pricesysc').removeAttr("disabled");
        $("#priceatag").css({"pointer-events": ""});
        sessionStorage.clear();
        // location.reload();
        document.getElementById("demo").innerHTML = "";
    }
    }, 1000);
    }
}
calltimer();
function pricecsvgenerate(obj)
{
  swal({   
        title: "Are you sure you want to Export Price csv?",   
        type: "warning",   
        showCancelButton: true,   
        confirmButtonColor: "#DD6B55",   
        confirmButtonText: "Yes, Export!",   
        closeOnConfirm: false 
    }, function(){
        var dt = new Date();
        // dt.setMinutes( dt.getMinutes()+1);;
        // var hour = oldDate.getHours()
        dt.setHours( dt.getHours()+1);
        sessionStorage.setItem("loginData",dt);
        $('#pricesysc').attr("disabled", true);
        $("#priceatag").css({"pointer-events": "none"});
        calltimer();
        // location.reload();
        var form_data = [{"name":"delid","value":obj}];
        var fewSeconds = 5;
        $.ajax({
            url: "apicron/fullfileMyboekenPrice",
            type: "POST",
            data: form_data,
            success: function (msg) {
                if(msg == 1)
                {
                     swal({
                        title: "Success!",   
                        text: "Successfully .",
                        type: "success", 
                        timer: 1000,   
                        showConfirmButton: false 
                        });
                        
                }
                return false;
            },
            async:false
        }); 
    });
}
</script>
Tags:
2 Comments
  • Robert Brown December 9, 2021

    Nam dui mauris, congue vel nisi in, tempus gravida enim. Nulla et tristique orci. Pellentesque lectus sapien, maximus id gravida sit amet, tristique non eros. Etiam aliquet, sem vitae sagittis convallis, ante sapien tincidunt nisl, eget dapibus tortor velit quis ex.

  • Ryan Berg December 9, 2021

    Proin et condimentum est, sed pretium ex. Mauris posuere est metus, vitae commodo sem posuere eget.

Leave a comment