简体   繁体   English

Fullcalendar - 将事件保存在数据库中

[英]Fullcalendar - save events in database

I have the following markup: 我有以下标记:

I have a instance of fullcalendar. 我有一个fullcalendar实例。 When clicking on a day (triggering the dayClick -callback), a bootstrap modal is opened, where the user can enter a title, and the start/end date. 单击一天(触发dayClick )时,将打开一个引导模式,用户可以在其中输入标题和开始/结束日期。 Once clicking on ok, those values provided, will be added to the calendar. 点击确定后,提供的这些值将被添加到日历中。 Here's the code for that: 这是代码:

 function addTitle(){ //having a button onClick="addTitle()"
            var title = $('#add_date_title').val();
            var startdate = $('#add_date_startdate').val();
            var enddate = $('#add_date_enddate').val();
            var end_split = enddate.split('-');
            end_split[2]= parseInt(end_split[2])+parseInt("1");
            enddate = end_split[0] + "-" + end_split[1] + "-" + end_split[2];
            $('#add_date_title').val('');
            $('#add_date_startdate').val('');
            $('#add_date_enddate').val('');
            $('#add_date_modal').modal('hide');

            var myCalendar = $('#calendar');
            var myEvent = {
                title:title,
                allDay: true,
                start: startdate,
                end: enddate
            };
            myCalendar.fullCalendar( 'renderEvent', myEvent );
        }

So the event is now in the calendar. 所以活动现在在日历中。 But when eg switching the month, or reloading the page, all data is lost, of course, because it's saved nowhere. 但是,当例如切换月份或重新加载页面时,所有数据都会丢失,当然,因为它没有保存。

Now the question is: How could I save the event directly into the database, and then load it, so where can I bring in php code, to save the event to a db... The problem, why I'm asking, is that the site in between adding events is never reloaded, so I'm not able, to check for GET or POST-Parameters or something similiar... Could I maybe do this with AJAX? 现在的问题是:如何将事件直接保存到数据库中,然后加载它,那么我可以在哪里引入PHP代码,将事件保存到数据库...问题,为什么我问,是添加事件之间的网站永远不会重新加载,所以我无法检查GET或POST参数或类似的东西......我可以用AJAX做这个吗? If yes, how? 如果有,怎么样? Because I'm not really familiar with AJAX. 因为我对AJAX并不熟悉。

You can actually save the events in DB. 您实际上可以将事件保存在DB中。

  1. Use this ajax after your modal trigger. 在模态触发后使用此ajax。
  2. Get the values like title,startdate, end date in modal and send them in the following ajax 以模态获取title,startdate,end date等值,并将其发送到以下ajax中

     $.ajax({ url: 'add_events.php', data: 'title='+ title+'&start='+ start2 +'&end='+ end2, type: "POST", success: function(json) { $( "#getReason" ).modal('hide'); $('#mydiv').hide(); $('body').removeClass('blockMask');//calendar.fullCalendar( 'refetchEvents'); $('#calendar').fullCalendar('refetchEvents'); } }); 
  3. in add_events.php save the details in db 在add_events.php中保存db中的详细信息

  4. In your main page use this method for dynamically creating event source 在主页面中使用此方法动态创建事件源

     function eventSourceCall(){ eventSourceCall = [ { url: 'events.php?status=absent', backgroundColor: 'red', borderColor: 'white', textColor: 'white', rendering: 'background', cache: false } 
  5. in events.php perform a select operation and retrieve the event parameters as json encoded objects and return them. 在events.php中执行select操作并将事件参数检索为json编码对象并返回它们。

  6. In calendar function eventSources: eventSourceCall, add this line for selecting the event source. 在日历函数eventSources: eventSourceCall,添加此行以选择事件源。

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

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