Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing values from client to server and back to client, asynchronously
    primarykey
    data
    text
    <p>I've been trying to figure this problem out for quite a while. I know JavaScript is client side scripting and PHP is server-side scripting, but is it possible to pass a browsers epoch time into a PHP script to run some calculations then return geoJSON data based on the results; all asynchronously?</p> <p>The function I want to pass to the PHP script is something like:</p> <pre><code>function retreiveUTC() { var now = new Date().getTime(); var browserUTC = Math.floor(now)/1000.0; // this returns epoch time of the browser } </code></pre> <p>Then I would like to take the epoch time that is generated from the function and pass it to a php script to determine what JSON file to return.</p> <p>For example I will have the following files residing on the server:</p> <pre> 1352188536.JSON 1352187536.JSON 1352177536.JSON </pre> <p>And I want to retrieve the one that is closest to the browsers epoch results. Thank you in advance.</p> <p>Updated code below:</p> <p>not sure what I am doing wrong, but I am getting success from the ajax call but the return value is undefined.</p> <p>ajax stuff:</p> <pre><code> $.post ('timezone.php', { epochTime: browserUTC }, function (result) { //do someting to result }, "json"); var browserUTC = new Date().getTime(); $.post ('timezone.php', { epochTime: browserUTC }, function (result,status) { //display file name returned by PHP alert(result.file + "\n" + status); //console.log('test'); }); </code></pre> <p>PHP:</p> <pre><code> &lt;?php $epochTime = round($_POST['epochTime'] / 1000); $res= array(); $res['file'] = $epochTime . '.JSON'; return json_encode($res); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload