问题
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