我在我的项目中使用了 jQuery 完整日历。我的事件存储在 MS SQL Server 表(事件)中,我以“json”格式获取数据,但它没有呈现到完整日历中,事件也没有添加到表中... . 请任何机构可以帮助我....
CREATE TABLE events (
id NUMERIC IDENTITY(1,1) NOT NULL,
title varchar(255) NOT NULL,
start_event datetime NOT NULL,
end_event datetime NOT NULL,
CONSTRAINT [PK_events] PRIMARY KEY CLUSTERED
(
id ASC
)
)
INSERT INTO events(title,start_event,end_event) VALUES
('meeting1', '2019-07-31 00:00:00', '2019-07-31 00:00:00'),
('meeting2', '2019-08-09 00:00:00', '2019-08-09 00:00:00');
应用程序/视图/index.php:
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
editable:true,
header:{
left:'prev,next today',
center:'title',
right:'month,agendaWeek,agendaDay'
},
events: {
url : '<?php echo site_url('Home/load');?>',
error: function()
{
alert("error");
},
success: function()
{
console.log("successfully loaded");
}
},
selectable:true,
selectHelper:true,
select: function(start, end, allDay)
{
var title = prompt("Enter Event Title");
if(title)
{
var start = $.fullCalendar.formatDate(start,"Y-MM-DD HH:mm:ss");
var end = $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss");
$.ajax({
url:"<?php echo site_url('Home/valid_calendar');?>",
type:"POST",
data:{title:title, start:start, end:end},
success:function()
{
calendar.fullCalendar('refetchEvents');
alert("Added Successfully");
}
})
}
},
应用程序/视图/load.php:
$timezone = new DateTimeZone("UTC");
$sql = "select * from events";
$stmt = sqlsrv_query($conn,$sql);
if($stmt == false)
{
die(print_r(sqlsrv_errors(),true));
}
Smart猫小萌