我正在尝试使用fullcalendar惊人的jquery日历插件为我的应用程序,但我有麻烦从SQL Server在我的日历生成事件。
下面是我的代码:第一个JS$(document).ready(function() {
var date = new Date();
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
droppable: true,
eventLimit: true,
eventsources: 'events.php'
});
});
第二个events.php文件
<?php
$serverName = "ADMIN-PCSQLEXPRESS"; //serverNameinstanceName
$connectionInfo = array( "Database"=>"testing", "UID"=>"sa", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
} else {
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$sql = "SELECT id, custcode, title, description, datetime, status
FROM dbo.calls";
$stmt=sqlsrv_query($conn, $sql);
// Initializes a container array for all of the calendar events
$jsonArray = array();
while($row = sqlsrv_fetch_array($stmt))) {
$custcode = $row['custcode'];
$date = $row['datetime'];
// Stores each database record to an array
$buildjson = array('title' => "$custcode", 'start' => "$date", 'allday' => false);
// Adds each array into the container array
array_push($jsonArray, $buildjson);
}
// Output the json formatted data so that the jQuery call can read it
echo json_encode($jsonArray);
?>
目前我没有得到任何事件或错误!帮助! !
谢谢大家
似乎您需要在这里显式地将日期转换为字符串:
'start' => "$date"
:
'start' => $date->format('Y-m-d H:i:s');