0

我目前正在尝试为 FullCalendar 创建一个 JSON 提要。我目前有一个工作示例,但是输出不会将我的数据库放入日历中。有人有想法么?我现在一直坚持这个..

在我的代码中:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <link href='css/fullcalendar.css' rel='stylesheet' />
  <script src='js/jquery-1.9.1.min.js'></script>
  <script src='js/jquery-ui-1.10.2.custom.min.js'></script>
  <script src='js/fullcalendar.min.js'></script>
  <script>

$(document).ready(function() {

    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();

    var calendar = $('#calendar').fullCalendar({
        editable: true,

        events : "test1.php",
    eventClick: function(event) {
            // opens events in a popup window
            window.open(event.url, '', 'width=700,height=600');
            return false;
        },

        loading: function(bool) {
            if (bool) {
                $('#loading').show();
            }else{
                $('#loading').hide();
            }
        }   

    });

});

   </script>
    <style>

body {
    margin-top: 40px;
    text-align: center;
    font-size: 14px;
    font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
    }

#calendar {
    width: 900px;
    margin: 0 auto;
    }

   </style>
   </head>
    <body>
   <div id='calendar'></div>
   </body>
   </html>

test1.php 的代码

 $link = mysql_connect('localhost','root','abc123');
 if (!$link) { die('Could not connect: ' . mysql_error()); }
 mysql_select_db('trainingcourse');

 $result = mysql_query("SELECT * FROM tbl_course ");

 Initializes a container array for all of the calendar events
 $jsonArray = array();

  while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  {
   $eventtest = $row['courseid'];
   $startdate = $row['startdate'];
   $starttime = $row['starttime'];
     $enddate = $row['enddate'];
     $endtime = $row['endtime'];

    // Stores each database record to an array
    $buildjson = array('courseid' => "$eventtest", 'startdate' => "$startdate", 'enddate' => "$enddate", 'allday' => false);

    // Adds each array into the container array
    array_push($jsonArray, $buildjson);
      }
    // Output the json formatted data so that the jQuery call can read it
    echo json_encode($jsonArray);
       ?>

它无法在日历上显示。

我非常感谢您的帮助。

4

2 回答 2

0

你能试试这个吗?

<?php 
 $link = mysql_connect('localhost','root','abc123');
 if (!$link) { die('Could not connect: ' . mysql_error()); }
 mysql_select_db('trainingcourse',$link);

 $result = mysql_query("SELECT * FROM tbl_course ");


  while($row = mysql_fetch_assoc($result, MYSQL_ASSOC))
  {
   $eventtest = $row['courseid'];
   $startdate = $row['startdate'];
   $starttime = $row['starttime'];
     $enddate = $row['enddate'];
     $endtime = $row['endtime'];

    // Stores each database record to an array
    $buildjson[] = array(
                         'courseid'  => $eventtest, 
                         'startdate' => $startdate, 
                         'enddate'   => $enddate, 
                         'allday'    => false
                         );


  }
    // Output the json formatted data so that the jQuery call can read it
    echo json_encode($buildjson);
       ?><br>

希望它有效。也请尝试打印结果print_r($buildjson);

于 2013-10-29T04:07:34.563 回答
0

试试这个,它对我有用

在您的 PHP 代码上: header('Content-Type: application/json');

回声 json_encode($jsonArray);

在您的 html 代码上:将此选项添加到您的日历:eventSources:[

            // your event source
            {
                url: 'url/of/your/jsonphp',
                type: 'POST',
                data: {
                    custom_param1: 'something',
                    custom_param2: 'somethingelse'
                },
                error: function() {
                    alert('there was an error while fetching events!');
                },
                color: '#dadada',
                textColor: '#000000'
            }
于 2013-10-30T02:55:14.717 回答