我目前正在尝试为 FullCalendar 创建一个 JSON 提要。我目前有一个工作示例,但是输出不会将我的数据库放入日历中。有人有想法么?我现在一直坚持这个..
在我的代码中:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href='css/fullcalendar.css' rel='stylesheet' />
<script src='js/jquery-1.9.1.min.js'></script>
<script src='js/jquery-ui-1.10.2.custom.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<script>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
editable: true,
events : "test1.php",
eventClick: function(event) {
// opens events in a popup window
window.open(event.url, '', 'width=700,height=600');
return false;
},
loading: function(bool) {
if (bool) {
$('#loading').show();
}else{
$('#loading').hide();
}
}
});
});
</script>
<style>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
test1.php 的代码
$link = mysql_connect('localhost','root','abc123');
if (!$link) { die('Could not connect: ' . mysql_error()); }
mysql_select_db('trainingcourse');
$result = mysql_query("SELECT * FROM tbl_course ");
Initializes a container array for all of the calendar events
$jsonArray = array();
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$eventtest = $row['courseid'];
$startdate = $row['startdate'];
$starttime = $row['starttime'];
$enddate = $row['enddate'];
$endtime = $row['endtime'];
// Stores each database record to an array
$buildjson = array('courseid' => "$eventtest", 'startdate' => "$startdate", 'enddate' => "$enddate", '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);
?>
它无法在日历上显示。
我非常感谢您的帮助。