javascript - Updating php values using jquery -
<?php $date="2016-01-01"; ?> <script type="javascript"> $(document).ready(function(){ $('#prev').click(function(){ var myvar2=<?php echo json_encode($date);?>; alert(myvar2); var myvar=<?php $date2=date('y-m-d',strtotime('-1 day',strtotime($date))); $date=$date2; echo json_encode($date); ?>; alert(myvar); myvar2=<?php echo json_encode($date);?>; alert(myvar2); } }) </script> <input type="button" value="prev" id="prev" />
i need decrement value of variable date every time button id="prev"
clicked. problem here value of variable date not getting updated
if using sessions, need ajax call call php file within session update particular session variable. issue @ hand though not update until next time base page loaded since information need accessed.
in sample, need page say:
session_start();
and like:
$date = isset($_session["date"]) ? $_session["date"] : "2016-01-01";
and on front end need ajax post request file data key being "date":
session_start(); $_session["date"] = $_post["date"];
then each time load page, long session maintained keep date, default value being: "2016-01-01"
Comments
Post a Comment