Делаем аякс запрос, устанавливаем интервал повтора каждую секунду
Last active
May 26, 2021 15:33
-
-
Save konratnox/deb2f086b75b697b7da1 to your computer and use it in GitHub Desktop.
Таймер(заготовка)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timer = function() { | |
$.ajax({ | |
url: '/scripts/timer.php', | |
type: 'post', | |
dataType: 'json', | |
data: {}, | |
}) | |
.done(function(data) { | |
console.log("success"); | |
console.log(data); | |
}) | |
.fail(function() { | |
console.log("error"); | |
}) | |
.always(function() { | |
console.log("complete"); | |
}); | |
}; | |
setInterval(timer, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cur_date = new Datetime(); | |
$mess_about_sales = new Datetime('18.01.2016 14:00:00'); | |
$saleStart = new Datetime('21.01.2016 00:00:01'); | |
$tillStart = date_diff($cur_date, $mess_about_sales); | |
$tillSaleStart = date_diff($cur_date, $saleStart); | |
$salesEnd = new Datetime('23.01.2016 00:00:01'); | |
$result['cur_date'] = $cur_date->format('H:i:s'); | |
$result['mess_about_sales'] = $mess_about_sales->format('H:i:s'); | |
if($cur_date < $salesEnd) { | |
if($cur_date > $mess_about_sales) { | |
$result['timer'] = 1; | |
$result['sales_start_h'] = $tillSaleStart->format('%h'); | |
$result['sales_start_min'] = $tillSaleStart->format('%i'); | |
$tillSalesEnd = $cur_date->diff($salesEnd); | |
$daysTillEnd = $tillSalesEnd->format('%a'); | |
$result['sales_end_d'] = $daysTillEnd; | |
if( $daysTillEnd > 0 ) { | |
$result['sales_end_h'] = $tillSalesEnd->format('%h') + ($daysTillEnd*24); | |
} else { | |
$result['sales_end_h'] = $tillSalesEnd->format('%h'); | |
} | |
$result['sales_end_min'] = $tillSalesEnd->format('%i'); | |
} else { | |
$result['timer'] = 0; | |
$timeTillStartD = $tillStart->format('%a'); | |
$timeTillStartH = $tillStart->format('%h'); | |
$timeTillStartm = $tillStart->format('%i'); | |
$result['till_start_days_mes'] = $timeTillStartD; | |
$result['till_start_hours_mes'] = $timeTillStartH; | |
$result['till_start_min_mes'] = $timeTillStartm; | |
} | |
} else { | |
$result['salesOver'] = 1; | |
} | |
echo json_encode($result); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment