我需要通过ajax调用
设置jQuery datepicker插件允许的时间这是我的javascript:
var al = function(currentDateTime) {
$.post("getdate.php", function(data) {
$('#default_datetimepicker').datetimepicker({
allowTimes: data
});
});
};
$(function() {
$('#default_datetimepicker').datetimepicker({
allowTimes: [
'08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00',
'17:00'
],
formatTime: 'H:i',
formatDate: 'd.m.Y',
defaultTime: '08:00',
onChangeDateTime: al,
timepickerScrollbar: true
});
这是我在“getdate.php”中的php代码。
<?php
echo "'08:00', '09:00'";
?>
我试过了,
$times = array(
'08:00', '09:00'
);
json_encode($times);
但他们两个都没有用......(我正在使用这个插件'http://xdsoft.net/jqplugins/datetimepicker/')
答案 0 :(得分:0)
如果您想通过AJAX电话获取房产的价值,您必须确保在显示您的时间选择器之前完成并成功通话。我认为这种方法会导致延迟......
我想到了另一个解决方案:
如果要使allowTimes属性动态化,可以将HTML / JS脚本放入.php文件中,并在php中获取所需的时间后回显一下。
<?php
//index.php
//
// Put here your script to get the allowed times. You can store them in a database, and make a simple SELECT request.
$allowed_times= "['08:00', '09:00']";
?>
<!-- your HTML CODE -->
<!-- your HTML CODE -->
$(function() {
$('#default_datetimepicker').datetimepicker({
allowTimes: <?php echo $allowed_times; ?>,
formatTime: 'H:i',
formatDate: 'd.m.Y',
defaultTime: '08:00',
onChangeDateTime: al,
timepickerScrollbar: true
});
答案 1 :(得分:0)
dataType:&#34; json&#34;,
contentType:&#34; application / json;字符集= UTF-8&#34;,
所以这是我的js,
var al = function(currentDateTime) {
$.ajax({
url: 'getdate.php',
type: 'POST',
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data) {
alert(data);
$('#default_datetimepicker').datetimepicker({
allowTimes: data
});
}
});
};
$(function() {
$('#default_datetimepicker').datetimepicker({
allowTimes: [
'08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00',
'17:00'
],
formatTime: 'g:i A',
formatDate: 'd.m.Y',
defaultTime: '08:00',
onChangeDateTime: al,
timepickerScrollbar: true
});
});
这是我的php,
<?php
$times = array(
'08:00', '09:00'
);
echo json_encode($times);
?>