php - Set jQuery datepicker allowed times with ajax call -


i need set jquery datepicker plugin allowed times ajax call

this 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     }); 

and php code in "getdate.php".

<?php     echo "'08:00', '09:00'"; ?> 

and tried,

$times = array(     '08:00', '09:00' );  json_encode($times); 

but both of them didn't work... (i'm using plugin 'http://xdsoft.net/jqplugins/datetimepicker/')

if want value of property via ajax call have make sure call finished , successful before displaying time picker. think method can cause latency...

i thought of other solution :

if want make allowtimes property dynamic can put html/js script .php file , make echo of allowed times want after getting in php.

<?php //index.php // // put here script allowed times. can store them in database, , make simple select request. $allowed_times= "['08:00', '09:00']";  ?> <!-- html code -->  <!-- 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         }); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -