javascript - How to referesh a php page after reception of post from jquery -


i posting local time on client machine server using jquery. besides displaying local time through php, save in database on server side. display client's time correctly, need refresh php page after receiving post jquery. how can that? here code. tried use header("refresh:0"), didn't work.

<script type="text/javascript">   $(function(){     var d = new date();     var datestr = d.tostring()     $.post(window.location, {         datestr: datestr     }).success(function(data){         var res = $(data).filter('#divmessage').text();         alert(res);     }); }); </script>  <div id="divmessage"> <?php      $v2 = 'nothing!';     if(isset($_post["datestr"]) && strlen(trim($_post["datestr"])) > 0)     {         $dstr = $_post["datestr"];         $v2 = 'current date/time '.$dstr;         echo "<span style=\"color:green\">$v2</span>";         // need refresh page here!         //header("refresh:0");     }     echo "<span style=\"color:green\">$v2</span>"; ?>  </div> 

your scheme:

  1. javascript reads client's time
  2. sends client's time server ajax
  3. receives response server containing client time
  4. displays response on page

why? if want display client's time, why server need involved.

besides displaying local time through php, save in database on server side

i'm curious why want save client's time in database, assuming have reason, do:

  1. javascript reads client's time
  2. javascript displays client's time on page
  3. send time server ajax.
  4. server saves in db

there no need process response data coming server. client has info.

i tried use header("refresh:0"), didn't work.

it won't work tried because you're setting headers after content has been sent browser (blank space, html , javascript precedes header() call). if wish same php file displays html respond ajax queries, put php logic on top, nothing @ before opening <?php


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -