简体   繁体   English

全日历故障排除事件

[英]Trouble saving event in fullcalendar

I can save the event in my database but it saves a different date. 我可以将事件保存在数据库中,但是可以保存其他日期。

When I click on a date it asks for the event name and saves it. 当我单击一个日期时,它会询问事件名称并保存。 The event is saved on the current date of the day not on the day that I choose/click. 该事件保存在当天的当前日期,而不是我选择/单击的日期。

Also the time it saves on the database depends on the current time of the computer. 另外,它在数据库上保存的时间取决于计算机的当前时间。

I am using v2.1 我正在使用v2.1

Here's my code: 这是我的代码:

<!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({

        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },

        editable: true,
        events:  "http://localhost/fullcalendar/events.php",
        selectable:true,

        select: function(start,end,title,date){
            var title = prompt('Event Title:');
            //var eventData;
            if(title){
                 var start = $.fullCalendar.moment().format();
                 var end = $.fullCalendar.moment().format();
                 $.ajax({
                        url:'http://localhost/fullcalendar/add_events.php',
                        data: 'title=' + title +'&start='+ start +'&end='+ end,
                        type:"POST",
                        success: function(json){
                            alert('Added Sucessfully');
                        }   

                 });



                 eventData = {
                        title:title,
                        start:start,
                        end:end,

                 };
                 $('#calendar').fullCalendar('renderEvent', eventData, true); //this makes the event stick on the calendar but not save on the database
            }
                $('#calendar').fullCalendar('unselect');
        },

        eventLimit:true,        



    });


});

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

In select function you have the following code: select函数中,您具有以下代码:

var start = $.fullCalendar.moment().format();
var end = $.fullCalendar.moment().format();

This means that you are overriding the start and end parameters. 这意味着您将覆盖startend参数。 As you are using it, start and end will have the current datetime and not the datetime that the user has selected. 使用时, startend将具有当前日期时间,而不是用户选择的日期时间。

If you remove these two lines, it should work as expected. 如果删除这两行,它应该可以正常工作。

var start = $.fullCalendar.moment(start).format(YYYY/MM/DD);

var end = $.fullCalendar.moment(end).format(YYYY/MM/DD);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM