如何在Fullcalendar中保存事件?

时间:2014-09-13 11:47:58

标签: php jquery mysql fullcalendar

我在将事件保存到数据库时遇到问题。老实说,我不知道该怎么做。我能够在phpmyadmin中保存完整日历中的事件,但我的问题是如何从完整日历中保存事件。

<!DOCTYPE html>
 <html>
 <head>
  <meta charset='utf-8' />
  <link href='css/fullcalendar.css' rel='stylesheet' />
  <link href='css/fullcalendar.print.css' rel='stylesheet' media='print' />
  <script src='js/moment.min.js'></script>
  <script src='js/jquery.min.js'></script>
  <script src='js/fullcalendar.min.js'></script>

<script>

$(document).ready(function() {

    var calendar = $('#calendar').fullCalendar({
        editable: true,
        events:  "http://localhost/fullcalendar/events.php",

        //what goes here? :(
    });     
 });

</script>
<style>

body {
    margin: 0;
    padding: 0;
    font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
    font-size: 14px;
}

#calendar {
    width: 900px;
    margin: 40px auto;
}

</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

你必须进行ajax调用。

例如:

var title = event.title;
            var start = event.start.format();
            var end = (event.end == null) ? start : event.end.format();
            $.ajax({
                url: 'process.php',
                data: 'type=newtitle&title='+title+'&start='+start+'&end='+end+'&eventid='+event.id,
                type: 'POST',
                dataType: 'json',
                success: function(response){
                    if(response.status != 'success')                            
                    revertFunc();
                },......

在你的php文件中,你可以使用每个对象:

$type = $_POST['type'];

if($type == 'newtitle')
{

    $title = $_POST['title'];
    $insert = mysqli_query($con,"INSERT INTO mytable(`title`) VALUES('$title')");
    $lastid = mysqli_insert_id($con);
    echo json_encode(array('status'=>'success','eventid'=>$lastid));
}

答案 1 :(得分:-1)

var s ="[{'title':1,'description':'Test1','start':'2014-09-15 16:00:00'}]";
        var myObject = eval('(' + s + ')');

        $('#CalContainer').fullCalendar(
        {
            defaultView : 'aWeek',
            slotEventOverlap : false,
            weekends : true,
            allDaySlot : false,
            firstDay:1,
            minTime:"06:00:00",
            maxTime:"24:00:00",
            forceEventDuration:true,
            defaultTimedEventDuration:"01:00:00",
            contentHeight : "400px",
            events:myObject,

            eventClick: function(calEvent, jsEvent, view) 


    {
alert(calEvent);
}
});