В моем php-файле есть следующий код:
<div id="clockTimestamp" class="hidden"><?=$_SERVER['REQUEST_TIME'];?></div>
<div id="clock"></div>
Я использую плагин отсчета jquery из Кит Вуд и называю его так:
$('#countdown').countdown({until: until, serverSync: getServerTime});
И следующий код в файле js:
function getServerTime() {
var time = $('#clockTimestamp').html()*1000;
time = new Date(time);
return time;
}
Теперь мой вопрос: этот подход с $ _SERVER ['REQUEST_TIME'] OK или я должен сделать это так:
function getServerTime() {
var time = null;
$.ajax(
{
url: '../../_ajax/getServerTime.php',
async: false,
dataType: 'text',
success: function(text) {
time = new Date(text);
},
error: function(http, message, exc) {
time = new Date();
}
});
return time;
}