I am trying to get the server show the client's date and time, but that is not showing the correct output. Here is the relevant part of the code:
<script type="text/javascript">
$(function(){
var d = new Date();
var dateStr = d.toString()
$.post(window.location, {
dateStr: dateStr
});
alert(dateStr);
});
</script>
<div id="divMessage">
<?php
$dstr = 'nothing!';
if(isset($_POST["dateStr"]) && strlen(trim($_POST["dateStr"])) > 0)
$dstr = $_POST["dateStr"];
$v = 'current date/time is '.$dstr;
echo "<span style=\"color:green\">$v</span>";
?>
</div>
If the code is correct, I should see "current date time is <client's date/time>"
, but instead I see "current date time is nothing!"
. What mistake am I doing here?