本文介绍了FullCalendar:如何通过ajax响应在fullcalendar中显示事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在全日制工作。现在我需要通过ajax调用来显示数据库中的所有事件。到目前为止,我已经通过json从数据库中获取了事件。
在var_dump之后,我的json输出如下所示:

  array(size = 3)
0 = >
array(size = 7)
'title'=> string'hi'(length = 2)
'id'=> int 1
'start'=>字符串'2016-05-30 00:00:00.000'(length = 23)
'rendering'=>字符串'背景'(长度= 10)
'backgroundColor'=>字符串'#ff9999'(长度= 7)
'className'=>字符串'event-full'(长度= 10)
'textColor'=>字符串'white'(长度= 5)
1 =>
array(size = 7)
'title'=>字符串'vibrator'(长度= 8)
'id'=> int 3
'start'=>字符串'2016-05-26 00:00:00.000'(length = 23)
'rendering'=>字符串'背景'(长度= 10)
'backgroundColor'=>字符串'#ff9999'(长度= 7)
'className'=>字符串'event-full'(长度= 10)
'textColor'=>字符串'white'(长度= 5)
2 =>
array(size = 7)
'title'=>字符串'vibrator'(长度= 8)
'id'=> int 8
'start'=>字符串'2016-05-26 00:00:00.000'(length = 23)
'rendering'=>字符串'背景'(长度= 10)
'backgroundColor'=>字符串'#ff9999'(长度= 7)
'className'=>字符串'event-full'(长度= 10)
'textColor'=>字符串'white'(长度= 5)

和我的脚本通过我的ajax如下所示: -

  events:函数(开始,结束,时区,回调)
{
$ .ajax({
url:calendar / show_events,
type:'POST',//发送帖子数据
data:'type = fetch_events',
async:true,

success:function(s){

dynamic_events = s;
alert(dynamic_events);
// $('#calendar')。fullCalendar('addEventSource ',JSON.parse(dynamic_events));

var dynamic_events = [];
$(doc).find('event')。each(function(){
events.push($ {b $ b title:$(this).attr('title'),
start:$(this).attr('start')//将被解析
} );
});
callback(events);

}
});
}

我的代码中有什么错误..我现在想学习。
任何人都可以帮助我并挽救我的一天。
我需要在FullCalendar中显示所有事件。提前致谢

解决方案

将您的ajax代码更改为

<$ p $ $。ajax({
url:calendar / show_events,
type:'POST',//发送发布数据
data:'type = fetch_events ',
async:true,

success:function(s){

var dynamic_events = [];
$(s).find( '(event)'。each(function(){
dynamic_events.push({
title:$(this).attr('title'),
start:$(this).attr ('start')//将被解析
});
});
callback(dynamic_events);
$ b}
});


I am working in full calendar. Now i need to show up all the events from the database through the ajax call. Till now , i have taken the events from database through json.My json output is as follows after the var_dump:

array (size=3)
  0 =>
    array (size=7)
      'title' => string 'hi' (length=2)
      'id' => int 1
      'start' => string '2016-05-30 00:00:00.000' (length=23)
      'rendering' => string 'background' (length=10)
      'backgroundColor' => string '#ff9999' (length=7)
      'className' => string 'event-full' (length=10)
      'textColor' => string 'white' (length=5)
  1 =>
    array (size=7)
      'title' => string 'vibrator' (length=8)
      'id' => int 3
      'start' => string '2016-05-26 00:00:00.000' (length=23)
      'rendering' => string 'background' (length=10)
      'backgroundColor' => string '#ff9999' (length=7)
      'className' => string 'event-full' (length=10)
      'textColor' => string 'white' (length=5)
  2 =>
    array (size=7)
      'title' => string 'vibrator' (length=8)
      'id' => int 8
      'start' => string '2016-05-26 00:00:00.000' (length=23)
      'rendering' => string 'background' (length=10)
      'backgroundColor' => string '#ff9999' (length=7)
      'className' => string 'event-full' (length=10)
      'textColor' => string 'white' (length=5)

and my script through my ajax is as follows:-

 events: function(start, end, timezone, callback)
{
$.ajax({
        url: "calendar/show_events",
        type: 'POST', // Send post data
        data: 'type=fetch_events',
        async: true,

        success: function(s){

             dynamic_events =s;
                       alert(dynamic_events);
             // $('#calendar').fullCalendar('addEventSource', JSON.parse(dynamic_events));

              var dynamic_events = [];
                $(doc).find('event').each(function() {
                    events.push({
                        title: $(this).attr('title'),
                        start: $(this).attr('start') // will be parsed
                    });
                });
                callback(events);

              }
    });
}

What is the error in my code.. I want to learn now.Can anyone help me and save my day.I am in need to display all the events in the FullCalendar. Thanks In Advance

解决方案

Change your ajax code to that

$.ajax({
    url: "calendar/show_events",
    type: 'POST', // Send post data
    data: 'type=fetch_events',
    async: true,

    success: function(s){

          var dynamic_events = [];
            $(s).find('event').each(function() {
                dynamic_events.push({
                    title: $(this).attr('title'),
                    start: $(this).attr('start') // will be parsed
                });
            });
            callback(dynamic_events);

          }
});

这篇关于FullCalendar:如何通过ajax响应在fullcalendar中显示事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:18
查看更多