0

我正在尝试使用内置功能的“事件(作为 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);
4

3 回答 3

0

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"}]
于 2013-03-30T00:00:19.677 回答
0

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

于 2013-03-30T21:57:37.023 回答
0

我有同样的问题,这对我来说也是一个格式化问题。

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

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

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

于 2014-12-02T04:24:14.897 回答