【问题标题】:fullCalendar "events: 'somepage.php'" JSON Results not displayingfullCalendar "events: 'somepage.php'" JSON 结果未显示
【发布时间】:2013-03-29 11:21:02
【问题描述】:

我正在尝试使用内置功能的“事件(作为 JSON 提要)”为我的 fullCalendar 实现获取事件。

... 事件:'calendarFill.php', ...

php 文件返回以下 JSON 数据:

[{"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what's going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}]

上述方法不起作用 - 事件未显示在日历上。我在我的 Javascript 代码中剪切并粘贴了代码目录:

events: {"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what's going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}],

而且,它不显示。但是,如果我编辑上面的内容以删除所有不在文本值周围的引号(如下所示),它可以工作。

events: [{id:40,title:"test four",services:"Reflexology (40), foot-soak",start:"Tue Mar 26 2013 13:00:00",end:"Tue Mar 26 2013 13:40:00",color:"#e56b15",customerId:21,phone:"555-0404",email:"test4",notes:"test two of update. this sentence added at update.",seat:"Side Couch 9",vip:"yes",confirmed:"yes",knows_policies:"yes",customer_here:0,allDay:false},{id:41,title:"test four",services:"Foot-Soak, ",start:"Wed Mar 27 2013 19:00:00",end:"Wed Mar 27 2013 19:15:00",color:"#e56b15",customerId:21,phone:"555-0404",email:"test4",notes:"test of addslashes. what's going to happen?",seat:"Front Chair 2",vip:"yes",confirmed:"yes",knows_policies:"yes",customer_here:0,allDay:false}],

我正在使用此链接中的文档:http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

我做错了什么?我应该从我的 php 中删除 'json_encode' 并返回一个格式如上的字符串吗?我想以“正确”的方式来做这件事,而不是一些变通方法。

按要求添加了 php:

// for connection to db
include("../includes/config.php");
include("../includes/mysql_functions.php");

// connection with db
$linkID = db_connect();

$returnValue = array();

$getEventData = mysql_query("SELECT apt_num, services, apt_date_start, apt_date_end, therapist, customer_num, notes, seat, confirmed, knows_policies, here FROM appointments", $linkID);

if ($getEventData != FALSE && mysql_num_rows($getEventData) > 0)
{
    while ($theEventData = mysql_fetch_array($getEventData))
    {
        $getCustomerString = "SELECT first_name, middle_name, last_name, phone, email, vip FROM customer WHERE customer_num = ".$theEventData['customer_num'];
        $getCustomerData = mysql_query($getCustomerString, $linkID);

        if ($getCustomerData != FALSE && mysql_num_rows($getCustomerData) > 0)
        {
            while($theCustomerData = mysql_fetch_array($getCustomerData))
            {
                $customerName = $theCustomerData['first_name']." ".$theCustomerData['middle_name']." ".$theCustomerData['last_name'];
                $customerPhone = $theCustomerData['phone'];
                $customerEmail = $theCustomerData['email'];
                $customerVip = $theCustomerData['vip'];
            }
        }
        else
        {
            $customerName = "error";
            $customerPhone = "error";
            $customerEmail = "error";
            $customerVip = "error";
        }

        $rowArray['id'] = $theEventData['apt_num'];
        $rowArray['title'] = $customerName;
        $rowArray['services'] = $theEventData['services'];
        $rowArray['start'] = date("D", $theEventData['apt_date_start'])." ".date("M", $theEventData['apt_date_start'])." ".date("d", $theEventData['apt_date_start'])." ".date("Y", $theEventData['apt_date_start'])." ".date("H", $theEventData['apt_date_start']).":".date("i", $theEventData['apt_date_start']).":".date("s", $theEventData['apt_date_start']);
        $rowArray['end'] = date("D", $theEventData['apt_date_end'])." ".date("M", $theEventData['apt_date_end'])." ".date("d", $theEventData['apt_date_end'])." ".date("Y", $theEventData['apt_date_end'])." ".date("H", $theEventData['apt_date_end']).":".date("i", $theEventData['apt_date_end']).":".date("s", $theEventData['apt_date_end']);
        $rowArray['color'] = $theEventData['therapist'];
        $rowArray['customerId'] = $theEventData['customer_num'];
        $rowArray['phone'] = $customerPhone;
        $rowArray['email'] = $customerEmail;
        $rowArray['notes'] = $theEventData['notes'];
        $rowArray['seat'] = $theEventData['seat'];
        $rowArray['vip'] = $customerVip;
        $rowArray['confirmed'] = $theEventData['confirmed'];
        $rowArray['knows_policies'] = $theEventData['knows_policies'];
        $rowArray['customer_here'] = $theEventData['here'];
        $rowArray['allDay'] = "false";

        array_push($returnValue, $rowArray);
    }
}
else
{
    $returnValue[0] = "error";
}

print json_encode($returnValue);

【问题讨论】:

  • PHP 文件中有什么?
  • 习惯注释:Please, don't use mysql_* functions 在新代码中。它们不再被维护并且是officially deprecated。看到红框了吗?改为了解准备好的语句,并使用pdomysqli
  • 在运行这个的服务器上,'mysql_*' 函数不会成为问题。关于为什么 fullCalendar 没有按预期呈现事件的任何想法?

标签: php jquery json fullcalendar


【解决方案1】:

Markus Vetter(来自 Google+)发现了问题。在从我的 php 文件返回的原始代码中,有一个“'”会导致问题。在将其返回到 jQuery/Javascript 之前,我需要在我的 php 中添加斜杠。完成后,jQuery / fullCalendar 代码能够按预期呈现我的事件。

第二双眼睛创造奇迹!谢谢马库斯维特!

返回的原始代码:

[{"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what's going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}]

在我的 php 中对所有文本字段使用“addslashes”后:

[{"id":"40","title":"test four","services":"Reflexology (40), foot-soak","start":"Tue Mar 26 2013 13:00:00","end":"Tue Mar 26 2013 13:40:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test two of update. this sentence added at update.","seat":"Side Couch 9","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"},{"id":"41","title":"test four","services":"Foot-Soak, ","start":"Wed Mar 27 2013 19:00:00","end":"Wed Mar 27 2013 19:15:00","color":"#e56b15","customerId":"21","phone":"555-0404","email":"test4","notes":"test of addslashes. what\'s going to happen?","seat":"Front Chair 2","vip":"yes","confirmed":"yes","knows_policies":"yes","customer_here":"0","allDay":"false"}]

【讨论】:

  • 原来这不是答案。
【解决方案2】:

这次居然解决了!在我的 php 文件中,添加到 $rowArray 的最后一个值是:$rowArray['allDay'] = "false"。它不是文本值,而是实际的布尔值。这个 "$rowArray['allDay'] = false" 解决了这个问题。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,这对我来说也是格式问题。

    这就是我的 json 现在返回的方式,它终于可以工作了。

    [{"title":"Coke Trade Show","start":"2014-12-03"},{"title":"Michigan Show","start":"2014-12-04"}]
    

    将您的 json 返回直接粘贴到 JS 中以确保其正常工作绝对是个好主意。

    【讨论】:

      猜你喜欢
      • 2016-04-08
      • 2013-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-30
      相关资源
      最近更新 更多