fullcalendar不能使用php mysql

时间:2014-07-14 06:45:07

标签: fullcalendar

<!DOCTYPE html>
<html>
<head>
<link href='../fullcalendar.css' rel='stylesheet' />
<link href='../fullcalendar.print.css' rel='stylesheet' media='print' />
<script src='../lib/moment.min.js'></script>
<script src='../lib/jquery.min.js'></script>
<script src='../lib/jquery-ui.custom.min.js'></script>
<script src='../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,
   header: {
    left: 'prev,next today',
    center: 'title',
    right: 'month,agendaWeek,agendaDay'
   },

   events: "http://localhost/fullcalendar/demos/events.php",



   // Convert the allDay from string to boolean
   eventRender: function(event, element, view) {
    if (event.allDay === 'true') {
     event.allDay = true;
    } else {
     event.allDay = false;
    }
   },
   selectable: true,
   selectHelper: true,
   select: function(start, end, allDay) {
   var title = prompt('Sample Textbox:');
   if (title) {
   start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
   end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");
   $.ajax({
   url: 'http://localhost/fullcalendar/demos/add_events.php',
   data: 'title='+ title+'&start='+ start +'&end='+ end  ,
   type: "POST",
   success: function(json) {
   alert('Added Successfully');
   }
   });   
   calendar.fullCalendar('renderEvent',
   {
   title: title,
   start: start,
   end: end,
   allDay: allDay
   },
   true // make the event "stick"
   );
   }
   calendar.fullCalendar('unselect');
   },

   editable: true,
   eventDrop: function(event, delta) {
   var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
   var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
   $.ajax({
   url: 'http://localhost:8888/fullcalendar/update_events.php',
   data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
   type: "POST",
   success: function(json) {
    alert("Updated Successfully");
   }
   });
   },
   eventResize: function(event) {
   var start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
   var end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
   $.ajax({
    url: 'http://localhost:8888/fullcalendar/update_events.php',
    data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&id='+ event.id ,
    type: "POST",
    success: function(json) {
     alert("Updated Successfully");
    }
   });

}

  });

 });

</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>

我用php mysql实现了fullcallendar。我可以查询数据库并从table获取事件。但是我无法以正确的格式添加事件。

   start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
   end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");

如果我使用formatdata添加功能不工作。如果我删除它,它的工作,但插入db as 0000-00-00日期和时间。我不知道是做错了。我已经尝试了一切来解决这个问题可以有人帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

试试这个:

var start = Year+":"+Month+":"+Date+" "+hour+":"+min+":"+sec;
var end = Year+":"+Month+":"+Date+" "+hour+":"+min+":"+sec;   

相反

start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");

它适用于数据库插入

答案 1 :(得分:0)

在上一段代码之前添加:

var Year = date.getFullYear();
var Month = date.getMonth() + 1;
var Date = date.getDate();
var hour = date.getHours();
var min  = date.getMinutes();
var sec  = date.getSeconds();
相关问题