Fullcalendar - 保存在数据库中的事件 [英] Fullcalendar - save events in database

查看:538
本文介绍了Fullcalendar - 保存在数据库中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的标记:

我有fullcalendar的一个​​实例。 当每天点击(触发 dayClick -callback),自举模式被打开,用户可以在其中输入标题,和开始/结束日期。一旦点击OK,提供这些价值,将被添加到日历。这里的code为:

I have a instance of 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. 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 e.g. switching the month, or reloading the page, all data is lost, of course, because it's saved nowhere.

现在的问题是:我怎么能直接保存事件到数据库中,然后再加载,所以我在这里可以把在PHP code,将事件保存到数据库...问题,为什么我问,是将事件的网站是永远不会重新加载,所以我不能够,检查GET或POST参数或类似的东西...我可以也许做到这一点的AJAX?如果是的话,怎么样?因为我不是很熟悉AJAX。

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? If yes, how? Because I'm not really familiar with AJAX.

推荐答案

您可以真正保存事件数据库。

You can actually save the events in DB.

  1. 在乌拉圭回合模式触发后使用此阿贾克斯。
  2. 得到这样的称号,起始日期,结束日期,以模态的值,并将其发送给下面的AJAX

  1. Use this ajax after ur modal trigger.
  2. Get the values like title,startdate, end date in modal and send them in the following ajax

    $阿贾克斯({      网址:add_events.php,     数据:标题='+标题+'和;开始='+ START2 +'和末端='+ END2,键入:POST,       成功:函数(JSON){     $(#getReason).modal(隐藏);     $('#mydiv)隐藏()。     $(体)removeClass移除('blockMask'); // calendar.fullCalendar('refetchEvents');  $('#日历)fullCalendar('refetchEvents')。  }  });

$.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'); } });

在add_events.php保存在数据库中的信息

in add_events.php save the details in db

在您的主页上使用这种方法用于动态创建事件源

In your main page use this method for dynamically creating event source

函数eventSourceCall(){      eventSourceCall = [         {             网址:'?events.php状态=缺席,             的backgroundColor:'红',             BORDERCOLOR:白,             文字颜色:白,             渲染:背景,             缓存:假的         }

function eventSourceCall(){ eventSourceCall = [ { url: 'events.php?status=absent', backgroundColor: 'red', borderColor: 'white', textColor: 'white', rendering: 'background', cache: false }

在events.php进行选择操作和检索事件参数jscon EN codeD对象,并返回它们。

in events.php perform a select operation and retrieve the event parameters as jscon encoded objects and return them.

在压延机的功能 eventSources:eventSourceCall,添加此行选择的事件源

In calander function eventSources: eventSourceCall, add this line for selecting the event source.

这篇关于Fullcalendar - 保存在数据库中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆