Get jQuery UI Datepicker selected date to a PHP Session variable?

前提是你 提交于 2020-01-04 13:36:52

问题


How to get jQuery UI Datepicker selected date to a PHP Session variable when a date selected by user?


回答1:


Make an AJAX call when the onSelect is trigged.. Just dummy code you can play with:

        $('.selector').datepicker({
                 onSelect: function(dateText, inst) { 
                       $.ajax({
                             url: "myPHPscript.php?selecteddate=" + dateText,
                               success: function(){
                                 $(this).addClass("done");
                            }
                        });
                     }
        });



回答2:


Description

You can do this using Ajax. After the Datepicker is closed you can set the Session Variable using a Ajax call.

You can use the DatePicker event onClose if you want to set the variable after the dialog is closed or onSelect after a date is selected. I would prefer the onClose event.

Sample

jQuery

$('.selector').datepicker({
   onClose: function(dateText, inst) { 
      $.post("/backend.php", {"VariableName": dateText});
   }
});

PHP (backend.php)

<?php
    // set the variable
    $_SESSION['VariableName'] = $_POST['VariableName'];
?>

More Information

  • jQuery.ajax


来源:https://stackoverflow.com/questions/9159422/get-jquery-ui-datepicker-selected-date-to-a-php-session-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!