FullCalendarのeventsにphpを指定し、データベースからイベント読み込みを行おうとしています。
ドキュメントなどを参考に以下のようにコーディングしていますが、
eventsの読み込みでerrorになってしまいます。
HTML+JS
<div id='calendar'></div> <script> $(document).ready(function() { var calendar = $('#calendar').fullCalendar({ events: { url: 'scheduleevents.php', type: 'POST', // Send post data error: function() { alert('There was an error while fetching events.'); } } }); }); </script>
scheduleevents.php
try { // Connect to database $connection = connectDb(); // Prepare and execute query $query = "SELECT * FROM SCHEDULE"; $sth = $connection->prepare($query); $sth->execute(); // Returning array $events = array(); // Fetch results while ($row = $sth->fetch(PDO::FETCH_ASSOC)){ $e = array(); $e['num'] = $row['num']; $e['title'] = $row['title']; $e['start'] = $row['date']; $e['allDay'] = true; // Merge the event array into the return array array_push($events, $e); } // Output json for our calendar echo json_encode($events); exit(); } catch (PDOException $e){ echo $e->getMessage(); }
上記が動かないため、
scheduleevents.php側を以下のように固定値にしてみましたがそれでも読み込みません。
FullCalendar.jsは本日最新のものをアップしております。
scheduleevents.php(固定版)
<?php include ("../include.php"); // カレンダー開始日時 $start = date('Y-m-d H:i:s', $_GET['start']); // カレンダー終了日時の1秒前 $end = date('Y-m-d H:i:s', $_GET['end'] - 1); // イベントデータを出力 echo json_encode(array( array( 'title' => "start:" . $start, 'start' => $start ), array( 'title' => "end:" . $end, 'start' => $end, ) ));
回答1件
あなたの回答
tips
プレビュー