fullCalendar“events:'somepage.php'”JSON结果未显示

时间:2013-03-29 11:21:03

标签: php jquery json fullcalendar

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

3 个答案:

答案 0 :(得分:0)

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

第二双眼睛确实奇迹!谢谢Markus Vetter!

返回原始代码:

[{"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"}]

答案 1 :(得分:0)

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

答案 2 :(得分:0)

我遇到了同样的问题,这对我来说也是一种格式化的东西。

这就是我的json现在回归的方式,它终于有效了。

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

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