Reputation: 21
I am attempting to set FullCalendar businessHours dynamically.
businessHours: getBusinessHours(),
function getBusinessHours(){
$.ajax({
url:"../json_business_hours/json_business_hours.php",
type: "POST",
success:function(data){
console.log(data);
}
});
}
$host = 'localhost';
$username = '???????';
$password = '?????????????';
$dbname = '???????????';
$conn = new mysqli($host, $username, $password, $dbname);
if(!$conn)
{
die("Cannot connect to the database.". $conn->error);
}
$bh_sql = "SELECT day_no AS daysOfWeek, day_from AS startTime, day_to AS endTime FROM business_hours WHERE day_closed = 0";
$bh_result = mysqli_query($conn, $bh_sql);
$business_hours = array();
while($row =mysqli_fetch_assoc($bh_result))
{
$business_hours[] = $row;
}
echo json_encode($business_hours);
The specified business hours are not applied and I cannot see why. If I check the console.log output I get -
[{"daysOfWeek":[1],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[2],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[3],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[4],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[5],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[6],"startTime":"09:00:00","endTime":"13:00:00"}]
If I copy the console.log output and paste it in place of the function into my FullCalendar JS -
businessHours: [{"daysOfWeek":[1],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[2],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[3],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[4],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[5],"startTime":"09:00:00","endTime":"17:00:00"},
{"daysOfWeek":[6],"startTime":"09:00:00","endTime":"13:00:00"}],
The businessHours are applied correctly -
[FullCalendar with applied businessHours][1]
[1]: https://i.sstatic.net/jdUHc.png
Anyone have any ideas where I'm going wrong? Any suggestions/help would be greatly appreciated.
Upvotes: 0
Views: 155
Reputation: 21
In the end I solved the problem by running the PHP before loading the calendar. The PHP created an array - $business_hours. This is then used in FullCalendar - businessHours: ,
Upvotes: 1