/    Sign up×
Community /Pin to ProfileBookmark

live server time on page using AJAX and PHP

I’ve created the following which works reasonably.

AJAX:

[code]
<script type=”text/javascript”>
$(document).ready(function() {
function update() {
$.ajax({
type: ‘POST’,
url: ‘test22.php’,
timeout: 1000,
success: function(data) {
$(“#time”).html(data);
window.setTimeout(update, 1000);
},
});
}
update();
});
</script>
[/code]

PHP/ HTML:

[code]
<div id=”time”>
<?php
$timenow = date(‘H:i:s’);
echo $timemsg;
?>
</div>
[/code]

All is well in terms of XHR but the downside is the page takes a performance hit – buffer rapidly fill floating around the 65% to 72% as far as I recorded which was roughly 22.78 seconds

I wanted to use this to inform/ notify customers to complete their orders exactly 7 mins 0 seconds before 23:00pm and then on the dot 23:00:00 drop (slideDown) a dialog style modal using JQuery informing customers the store is not taking any further orders for the day -> ok -> enables them to just browser but not add anything to the cart

One way I thought was get the server time once and then run it on the client side but I not to sure as to how to even implement this..

Is there any solution, ideas, approach that someone could possibly throw my way?

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @nsath spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...