javascript - 在 FullCalendar 上获取事件

标签 javascript .net

我正在尝试让 FullCalendar 在我的应用程序上运行,但我无法获取 mysql 数据库上的事件。这是我的代码:

.cshtml

<div class="panel-body">
                    <script type="text/javascript">
                        $(document).ready(function () {
                            $('#calendar').fullCalendar({
                                height: 600,
                                width: 500,
                                theme: false,
                                fixedWeekCount: false,
                                header: {
                                    left: 'prev,next today',
                                    center: 'title',
                                    right: 'month,agendaWeek,agendaDay',

                                },
                                weekends: false,
                                editable: false,
                                eventSources: [

                                       'Agenda/getEvents'

                                ],
                            });
                        });
                    </script>
                    <div id="calendar"></div>
                </div>

.cs Controller

{
public class AgendaController : Controller
{
    // GET: Agenda
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Agenda()
    {
        ViewBag.id = Session["id"];
        ViewBag.usuario = Session["usuario"];
        ViewBag.tipo_usuario = Session["tipo_usuario"];
        return View();
    }

    [HttpPost]
    public JsonResult getEvents(double start, double end)
    {
        try
        {
            DataTable dt = new DataTable();


            using (MySqlConnection con = new MySqlConnection(BD.CadConMySQL()))
            {
                using (MySqlCommand cmd = new MySqlCommand("SELECT tareas.tipo as title, tareas.fecha_inicio as start, tareas.fecha_fin as end FROM tareas", con))
                {


                    using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                    }
                }
            }

            return Json(dt.ToList());
        }
        catch (Exception e)
        {
            RespGeneric resp = new RespGeneric("KO");
            resp.msg = e.Message;
            return Json(resp);
        }
    }

所以 Agenda/getEvents 给我返回了以下 JSON,对于 FullCalendar 来说似乎没问题: JSON

但是,日历没有显示任何事件,我不明白为什么,因为 JSON 看起来不错,如果我使用完全相同的数据在 .cshtml 上一一获取事件,它就会起作用。 谢谢!

最佳答案

我认为您没有尊重 documentation 中描述的标准 eventSource 获取的结构。如:

$('#calendar').fullCalendar({

  eventSources: [

    // your event source
    {
      url: '/myfeed.php',
      type: 'POST',
      data: {
        custom_param1: 'something',
        custom_param2: 'somethingelse'
      },
      error: function() {
        alert('there was an error while fetching events!');
      },
      color: 'yellow',   // a non-ajax option
      textColor: 'black' // a non-ajax option
    }

    // any other sources...

  ]

});

关于javascript - 在 FullCalendar 上获取事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45812194/

相关文章:

javascript - 使用正则表达式从 HTML 标签属性获取字符串 - JavaScript

javascript - Elasticsearch | "data"参数必须是字符串、TypedArray 或 DataView 类型之一

javascript - 在 Javascript 中使用 XMLHttpRequest 暂停下载

c# - 如何将 XMLDocument 反序列化为 C# 中的对象?

.net - 您可以舍入 .NET TimeSpan 对象吗?

.net - 单元测试项目找不到被测程序集(或依赖项)

c# - 使用 Streamreader 的输入不会在 StreamWriter 中给出相同的输出

c# - 在 .NET 中绘制文本

javascript - 从html表格中提取特定信息?

javascript - 更改 .js 文件时,Node.js 不重启服务器?