【问题标题】:fullcalendar not reading json events from mysql phpfullcalendar 没有从 mysql php 读取 json 事件
【发布时间】:2013-03-26 09:57:38
【问题描述】:

我正在尝试根据通过 php 从 mysql 中提取的数据预填充 fullcalendar。但是,该事件并未在完整日历中填充。 我的代码是:

 function invokeNewCal(elem)
 {
    var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();

        var calendar = $(elem).fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            selectable: true,
            selectHelper: true
            editable: true,
            events: {
        url: 'index.php?methodname=getevents'
        }
        });

 }

方法是:

function getevents($m,$n)
{
    echo json_encode(array('title'=>'Hello','start'=>'Wed, 10 Apr 2013 13:00:00 IST','end'=>'Wed, 10 Apr 2013 17:00:00 IST'));
}

这个 JSON 响应是:

{"title":"Hello","start":"Wed, 10 Apr 2013 13:00:00 IST","end":"Wed, 10 Apr 2013 17:00:00 IST"}

但是,该活动并未显示在 fullCalendar 上。知道我错过了什么吗?

谢谢

完整的请求/响应:

    Request URL:
    http://localhost/linkd/index.php?methodname=getevents&start=1364668200&end=1368297000&_=1365120846819

    Request Method:
    GET

    Status Code:
    HTTP/1.1 200 OK

    Request Headers
    05:44:26.000

  X-Requested-With:XMLHttpRequestUser-Agent:Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0Referer:http://localhost/linkd/schooladmin.phpHost:localhostConnection:keep-aliveAccept-Language:en-US,en;q=0.5Accept-Encoding:gzip, deflateAccept:application/json, text/javascript, */*; q=0.01

    Sent Cookie
    PHPSESSID:cs7ai8vreh43q9otaff91kpe67

    Response Headers
    Δ23ms

  X-Powered-By:PHP/5.3.21Server:Apache/2.2.21 (Win32) PHP/5.3.21Keep-Alive:timeout=5, max=99Date:Fri, 05 Apr 2013 00:14:26 GMTContent-Type:text/htmlContent-Length:95Connection:Keep-Alive

      Response Body
      Δ0ms

    {"title":"Hello","start":"Wed, 10 Apr 2013 13:00:00 EST","end":"Wed, 10 Apr 2013 17:00:00 EST"}

【问题讨论】:

标签: php mysql fullcalendar json


【解决方案1】:

我建议使用documentation 中指定的 ISO8601 标准。
如果您转到 Mahesh Sapkal 创建的 DEMO 并将那里的日期更改为标准,两者都会出现。
标准格式很简单:YYYY-MM-DDTHH:mm:ss 其中 T 是时间和日期之间的分隔符。

希望对你有帮助

【讨论】:

  • 根据以下响应更改为 ISO8601:{"title":"Hello","start":"2013-04-10T12:00:00","end":"2013-04 -10T15:00:00"} 但是该事件尚未显示:)
  • 您缺少 [] 括号。转到此link 以查看您提供的日期示例。
  • 您应该将 json_encode 数据作为数组放入数组中,如下所示: json_encrypt(array(array('title'=>'Hello','start'=>'2013-04-10T13: 00:00','end'=>'2013-04-10T17:00:00')));
【解决方案2】:

检查docevents:{url:xxx} 中有多余的大括号;而且在您的 json_response 中,您只编码一个事件:您需要它们的数组。

【讨论】:

    【解决方案3】:

    请将时区从 IST 更改为 EST。

    {
          "title":"Hello",
          "start":"Wed, 10 Apr 2013 13:00:00 EST",
          "end":"Wed, 10 Apr 2013 17:00:00 EST"
    }
    

    以下是演示,其中我们有两个事件,一个在 IST 中,另一个在 EST 中,但是仅显示 EST。

    DEMO

    【讨论】:

    • 您确定给定 url 的 ajax 请求正在触发并且它正在返回 JSON 响应。
    【解决方案4】:

    你好
    我遇到了同样的问题,解决方法是你需要使用events: JSON.parse(yourListOfEvents),否则它不起作用。

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 2012-09-08
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      相关资源
      最近更新 更多