How to create a ajax request to a file

How to make a reuqest once the timer reaches 0?

 <!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<?php

    date_default_timezone_set('America/Los_Angeles');
    $rawDateStart = date('F j, Y H:i:s', date_timestamp_get(DateTime::createFromFormat('F j, Y H:i:s', 'January 7, 2016 07:00:00')));
    $rawDateCurrent = date('F j, Y H:i:s');
?>

<script>
    var printSeconds, printMinutes, printHoursDaily, printHoursWeekly, printDays;

    // Get strating and current date
    var startDate = new Date("<? echo $rawDateStart; ?>");
    var currentDate = new Date("<? echo $rawDateCurrent; ?>");

    $(function(){    

        function calculateTime()
        {
            // Increment current time
            currentDate.setSeconds(currentDate.getSeconds() + 1);

            // Calcualte time passed since the start
            var timePassed = currentDate.getTime() - startDate.getTime();
            var secondsSinceStart = Math.floor(timePassed / 1000 );
            var minutesSinceStart = Math.floor(secondsSinceStart / 60);
            var hoursSinceStart = Math.floor(minutesSinceStart / 60);
            var daysSinceStart = Math.floor(hoursSinceStart / 24);

            // Calculate time since last daily (18h) reset
            var dailySecondsElapsed = secondsSinceStart % 60;
            var dailyMinutesElapsed = minutesSinceStart % 60;
            var dailyHoursElapsed = hoursSinceStart % 18;

            // Calculate time since last weekly (7d) reset
            var weeklyHoursElapsed = hoursSinceStart % 24;
            var weeklyDaysElapsed = daysSinceStart % 7;

            // Calculate remaining time until next daily (18h) reset
            var remainingSeconds = 59 - dailySecondsElapsed;
            var remainingMinutes = 59 - dailyMinutesElapsed;
            var remainingHoursDaily = 17 - dailyHoursElapsed;

            // Calculate remaining time until next weekly (7d) reset
            var remainingHoursWeekly = 23 - weeklyHoursElapsed;
            var remainingDays = 6 - weeklyDaysElapsed;

            // If any of the variables is only a single digit number, then add 0 before
            printSeconds = (remainingSeconds > 9) ? remainingSeconds : '0' + remainingSeconds;
            printMinutes = (remainingMinutes > 9) ? remainingMinutes : '0' + remainingMinutes;
            printHoursDaily = (remainingHoursDaily > 9) ? remainingHoursDaily : '0' + remainingHoursDaily;
            printHoursWeekly = (remainingHoursWeekly > 9) ? remainingHoursWeekly : '0' + remainingHoursWeekly;
            printDays = (remainingDays > 9) ? remainingDays : '0' + remainingDays;
        }

        setInterval(function() {
            calculateTime();

            // Print
            jQuery('#daily p').html(printHoursDaily+':'+printMinutes+':'+printSeconds)
            jQuery('#weekly p').html(printDays+':'+printHoursWeekly+':'+printMinutes+':'+printSeconds)
        }, 1000);
    });
</script>

<div id="daily"><p ></p></div>
<div id="weekly"><p ></p></div>

</body

https://api.jquery.com/jquery.ajax/

Sponsor our Newsletter | Privacy Policy | Terms of Service