I used jQuery Full Calendar in my project.My events are stored in MS SQL Server table(events), I got the data in "json" format, but it is not render into Full calendar and events are not added into table.... Please can any body help me....
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');
application/views/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");
}
})
}
},
application/views/load.php:
$timezone = new DateTimeZone("UTC");
$sql = "select * from events";
$stmt = sqlsrv_query($conn,$sql);
if($stmt == false)
{
die(print_r(sqlsrv_errors(),true));
}
while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
{
$data[] = array(
'title' => $row['title'],
'start_event' => $row['start_event']->format("Y-m-d H:i:s"),
'end_event' => $row['end_event']->format("Y-m-d H:i:s")
);
}
echo json.parse($data);
My Error:
Uncaught TypeError: Cannot read property 'hasTime' of undefined
I thought PHP datetime and Sql Server datetime are mismatched... So I added following code in events load.php
$timezone = new DateTimeZone("UTC");
$data[] = array(
'title' => $row['title'],
'start_event' => $row['start_event']->format("Y-m-d H:i:s"),
'end_event' => $row['end_event']->format("Y-m-d H:i:s")
);
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
editable:true,
header:{
left:'prev,next today',
center:'title',
right:'month,agendaWeek,agendaDay'
},
events:" <?php echo site_url('Home/load');?>",
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");
}
It gives me output as:
[
{"title":"hi","start_event":"2019-07-31 00:00:00","end_event":"2019-07-31 00:00:00"},
{"title":"dsfdfdfd","start_event":"2019-08-09 00:00:00","end_event":"2019-08-09 00:00:00"}
]
But in my url: http://localhost/calendar_sql/index.php/Home/load?start=2019-06-30&end=2019-08-11&_=1564490059946
In my url I don't passed this data anywhere start=2019-06-30&end=2019-08-11