如何让FullCalendar显示来自我的JSON提要的信息?

时间:2023-01-25 07:27:05

I'm setting up an app using FullCalendar (http://arshaw.com/fullcalendar/) that will allow the user to see client scheduling information as well as schedule clients through a management interface.

我正在使用FullCalendar(http://arshaw.com/fullcalendar/)设置应用程序,该应用程序将允许用户查看客户端调度信息以及通过管理界面调度客户端。

I want to use a MySQL database to populate an array, and then pass that array in the form of a JSON feed to FullCalendar on an HTML page. Ideally, then, the client information would show up on the HTML page. However, even though my JSON feed is being passed, there are no events on my FullCalendar.

我想使用MySQL数据库来填充数组,然后将该数组以JSON提要的形式传递给HTML页面上的FullCalendar。理想情况下,客户端信息将显示在HTML页面上。但是,即使我的JSON提要被传递,我的FullCalendar上也没有事件。

Example JSON feed being passed:

传递的示例JSON提要:

[{"title":"Watson","start":"1333976400","end":"1333980000","allDay":false}]

I'm fairly new to these languages and I would not be surprised if this mistake turn out to be simple.

我对这些语言还比较陌生,如果这个错误变得简单,我也不会感到惊讶。

I would deeply appreciate any help or insight on having these events show up. When I manually feed an array into FullCalendar, it does show the events, but so far my JSON feed has resulted in no information being displayed.

我非常感谢有关这些活动出现的任何帮助或见解。当我手动将数组提供给FullCalendar时,它确实显示了事件,但到目前为止,我的JSON提要导致没有显示任何信息。

Thank you

谢谢

For reference: HTML:

供参考:HTML:

        $(document).ready(function() {      
        $('#calendar').fullCalendar({
            events: '/json-events.php'
        });     
});

PHP:

PHP:

        while ($record = mysql_fetch_array($result)) {
        $event_array[] = array(
            'id' => $record['id'],
            'title' => $record['title'],
            'start' => $record['start_date'],
            'end' => $record['end_date'],
            'allDay' => false
        );
    }

echo json_encode($event_array);

3 个解决方案

#1


7  

So the problem, for those searchers that come after me, was that my PHP file had HTML head and body tags. I'm a PHP noob and so I didn't know that would cause it not to work. In order for FullCalendar to display the JSON feed, it must ONLY have PHP code, no HTML. JSONLint.com was invaluable in figuring that out.

因此,对于那些追随我的搜索者来说,问题在于我的PHP文件具有HTML头部和正文标记。我是一个PHP菜鸟,因此我不知道会导致它无法正常工作。为了让FullCalendar显示JSON提要,它必须只有PHP代码,没有HTML。 JSONLint.com在确定这一点时非常宝贵。

#2


5  

I set up a quick example and didn't have any trouble getting this to work:

我设置了一个快速示例,并且没有任何问题让这个工作:

PHP:

PHP:

<?php

$record[0]["title"]="Test 1";
$record[1]["title"]="Test 2";
$record[2]["title"]="Test 3";

$record[0]["start_date"]="1333976400";
$record[1]["start_date"]="1333976401";
$record[2]["start_date"]="1333976402";

$record[0]["end_date"]="1333980000";
$record[1]["end_date"]="1333980001";
$record[2]["end_date"]="1333980002";

$record[0]["id"]="1";
$record[1]["id"]="2";
$record[2]["id"]="3";

for ($i=0; $i<3; $i++) {

    $event_array[] = array(
            'id' => $record[$i]['id'],
            'title' => $record[$i]['title'],
            'start' => $record[$i]['start_date'],
            'end' => $record[$i]['end_date'],
            'allDay' => false
    );


}

echo json_encode($event_array);


exit;

?>

HTML:

HTML:

events: '/events.php'

Sample output from the PHP script:

PHP脚本的示例输出:

[{"id":"1","title":"Test 1","start":"1333976400","end":"1333980000","allDay":false},{"id":"2","title":"Test 2","start":"1333976401","end":"1333980001","allDay":false},{"id":"3","title":"Test 3","start":"1333976402","end":"1333980002","allDay":false}]

So given that the above works for me and it's really no different to what you have above, you might need to check that the PHP script is actually getting called correctly. Check the Javascript console in Mozilla Firefox or Google Chrome to see if there are any errors thrown when Fullcalendar tries to load the events. Check your web server access/error logs for any mention of the PHP script.

因此,鉴于以上内容对我而言并且与上面的内容完全没有区别,您可能需要检查PHP脚本是否正在被正确调用。检查Mozilla Firefox或Google Chrome中的Javascript控制台,查看Fullcalendar尝试加载事件时是否存在任何错误。检查您的Web服务器访问/错误日志,以获取有关PHP脚本的任何提及。

#3


1  

events: '/json-events.php'

should be either

应该是

events: './json-events.php'

or

要么

events: 'json-events.php'

Let me know if this helps...

如果这有帮助,请告诉我......

EDIT

编辑

I also noticed that in the Json that your are receiving there is no id in the line. There may be something going on between the nameing of you id within the DB comparitively to the name your using in the array. Check it out and see if that is what is going on, because that is one of the properties that are required to pass the event.

我还注意到,在你收到的Json中,行中没有id。数据库中您的ID名称与您在数组中使用的名称之间可能存在某种关系。检查一下,看看是否发生了这种情况,因为这是传递事件所需的属性之一。

EDIT

编辑

Try removing the [] from $event_array[] and see what happens... If that doesn't work than I am stumpped... sorry

尝试从$ event_array []中删除[],看看会发生什么......如果这不起作用,我会被困住...抱歉

#1


7  

So the problem, for those searchers that come after me, was that my PHP file had HTML head and body tags. I'm a PHP noob and so I didn't know that would cause it not to work. In order for FullCalendar to display the JSON feed, it must ONLY have PHP code, no HTML. JSONLint.com was invaluable in figuring that out.

因此,对于那些追随我的搜索者来说,问题在于我的PHP文件具有HTML头部和正文标记。我是一个PHP菜鸟,因此我不知道会导致它无法正常工作。为了让FullCalendar显示JSON提要,它必须只有PHP代码,没有HTML。 JSONLint.com在确定这一点时非常宝贵。

#2


5  

I set up a quick example and didn't have any trouble getting this to work:

我设置了一个快速示例,并且没有任何问题让这个工作:

PHP:

PHP:

<?php

$record[0]["title"]="Test 1";
$record[1]["title"]="Test 2";
$record[2]["title"]="Test 3";

$record[0]["start_date"]="1333976400";
$record[1]["start_date"]="1333976401";
$record[2]["start_date"]="1333976402";

$record[0]["end_date"]="1333980000";
$record[1]["end_date"]="1333980001";
$record[2]["end_date"]="1333980002";

$record[0]["id"]="1";
$record[1]["id"]="2";
$record[2]["id"]="3";

for ($i=0; $i<3; $i++) {

    $event_array[] = array(
            'id' => $record[$i]['id'],
            'title' => $record[$i]['title'],
            'start' => $record[$i]['start_date'],
            'end' => $record[$i]['end_date'],
            'allDay' => false
    );


}

echo json_encode($event_array);


exit;

?>

HTML:

HTML:

events: '/events.php'

Sample output from the PHP script:

PHP脚本的示例输出:

[{"id":"1","title":"Test 1","start":"1333976400","end":"1333980000","allDay":false},{"id":"2","title":"Test 2","start":"1333976401","end":"1333980001","allDay":false},{"id":"3","title":"Test 3","start":"1333976402","end":"1333980002","allDay":false}]

So given that the above works for me and it's really no different to what you have above, you might need to check that the PHP script is actually getting called correctly. Check the Javascript console in Mozilla Firefox or Google Chrome to see if there are any errors thrown when Fullcalendar tries to load the events. Check your web server access/error logs for any mention of the PHP script.

因此,鉴于以上内容对我而言并且与上面的内容完全没有区别,您可能需要检查PHP脚本是否正在被正确调用。检查Mozilla Firefox或Google Chrome中的Javascript控制台,查看Fullcalendar尝试加载事件时是否存在任何错误。检查您的Web服务器访问/错误日志,以获取有关PHP脚本的任何提及。

#3


1  

events: '/json-events.php'

should be either

应该是

events: './json-events.php'

or

要么

events: 'json-events.php'

Let me know if this helps...

如果这有帮助,请告诉我......

EDIT

编辑

I also noticed that in the Json that your are receiving there is no id in the line. There may be something going on between the nameing of you id within the DB comparitively to the name your using in the array. Check it out and see if that is what is going on, because that is one of the properties that are required to pass the event.

我还注意到,在你收到的Json中,行中没有id。数据库中您的ID名称与您在数组中使用的名称之间可能存在某种关系。检查一下,看看是否发生了这种情况,因为这是传递事件所需的属性之一。

EDIT

编辑

Try removing the [] from $event_array[] and see what happens... If that doesn't work than I am stumpped... sorry

尝试从$ event_array []中删除[],看看会发生什么......如果这不起作用,我会被困住...抱歉