JavaScript - jQuery - PHP: dynamically display specific time in my datetimepicker from database

I have a jQuery datetimepicker using the xdsoft plugin . I only want to display specific hours / times that have been stored in my database (using php).

Example if I have values ​​in my database:

'12:00', '13:00', '15:00', 
'17:00', '17:05', '17:20', '19:00', '20:00'

      

And this is my jQuery for datetimepicker:

$('#datetimepicker1').datetimepicker({
  formatDate:'Y/MMM/d',
  allowTimes:[
    '12:00', '13:00', '15:00', 
    '17:00', '17:05', '17:20', '19:00', '20:00'
  ],
});

      

My problem is that I cannot use the technique to get time values ​​from my database and integrate it into my jQuery. This is what I want:

allowTimes:[my time values in my database],

      

PLEASE HELP ME: '(

Thank.

+3


source to share


1 answer


You can bind the datepick in ajax callback:



$.ajax({
  method: 'GET',
  url: 'gettimes.php'
}).done(function(response){
  $('#datetimepicker1').datetimepicker({
  formatDate:'Y/MMM/d',
  allowTimes:[
     response //JSON STRING with allowed Times
   ]
  });
});

      

+1


source







All Articles