0
大家好我現在深化發展與規劃模塊 我使用Fullcalendar JS打造規劃一些日曆 一個應用程序,我發現這個代碼Fullcalendar PHP MySQL的JSON
initCalendar: function() {
if (!jQuery().fullCalendar) {
return;
}
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var h = {};
if ($('#calendar').width() <= 400) {
$('#calendar').addClass("mobile");
h = {
left: 'title, prev, next',
center: '',
right: 'today,month,agendaWeek,agendaDay'
};
} else {
$('#calendar').removeClass("mobile");
if (App.isRTL()) {
h = {
right: 'title',
center: '',
left: 'prev,next,today,month,agendaWeek,agendaDay'
};
} else {
h = {
left: 'title',
center: '',
right: 'prev,next,today,month,agendaWeek,agendaDay'
};
}
}
$('#calendar').fullCalendar('destroy'); // destroy the calendar
$('#calendar').fullCalendar({ //re-initialize the calendar
disableDragging: false,
header: h,
editable: true,
events: [{
title: 'All Day Event',
start: new Date(y, m, 1),
backgroundColor: App.getLayoutColorCode('yellow')
}, {
title: 'Long Event',
start: new Date(y, m, d - 5),
end: new Date(y, m, d - 2),
backgroundColor: App.getLayoutColorCode('green')
}, {
title: 'Repeating Event',
start: new Date(y, m, d - 3, 16, 0),
allDay: false,
backgroundColor: App.getLayoutColorCode('red')
}, {
title: 'Repeating Event',
start: new Date(y, m, d + 4, 16, 0),
allDay: false,
backgroundColor: App.getLayoutColorCode('green')
}, {
title: 'Meeting',
start: new Date(y, m, d, 10, 30),
allDay: false,
}, {
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
backgroundColor: App.getLayoutColorCode('grey'),
allDay: false,
}, {
title: 'Birthday Party',
start: new Date(y, m, d + 1, 19, 0),
end: new Date(y, m, d + 1, 22, 30),
backgroundColor: App.getLayoutColorCode('purple'),
allDay: false,
}, {
title: 'Click for Google',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
backgroundColor: App.getLayoutColorCode('yellow'),
url: 'http://google.com/',
}
]
});
},
所以我做了一個PHP腳本返回的事件JSON格式
<?php
require_once("inc/db_const.php");
try {
$connection= new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$query = "SELECT id,title,start,end FROM events";
$sth = $connection->prepare($query);
$sth->execute();
$events = array();
$sth->bind_result($id,$title,$start,$end);
while($sth->fetch()) {
$e = array();
$e['id'] = $id;
$e['title'] = "Lorem Ipsum";
$e['start'] = $start;
$e['end'] =$end;
$e['allDay'] = false;
// Merge the event array into the return array
array_push($events, $e);
}
// Output json for our calendar
echo json_encode($events);
exit();
} catch (PDOException $e){
echo $e->getMessage();
}
?>
誰能幫助我如何能fullcalnder的代碼靜態值的JSON retrun從PHP改變
你想獲得通過AJAX的JSON數據? – 2014-10-28 12:51:31
是@Rik_s我這是我的問題 – EMIN 2014-10-28 12:52:27