뭔가 빠졌다고 생각합니다. 전체 일정을 설정하고 기본 버전을 사용하고 있지만 현재 JSON을 추가하고 있습니다. 일정 페이지에서FullCalendar JSON에 캘린더가 채워지지 않습니다.
코드 내가 함께 갈로 JSON을 인코딩하는 방법을 배우고, 내가 나에게 작동하는 것 같다 몇 가지 코드를 준 튜토리얼 온라인을 발견
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listWeek'
},
defaultDate: '2017-09-12',
editable: true,
navLinks: true, // can click day/week names to navigate views
eventLimit: true, // allow "more" link when too many events
events: {
url: 'php/get-events.php',
error: function() {
$('#script-warning').show();
}
},
loading: function(bool) {
$('#loading').toggle(bool);
}
});
});
입니다. 나는 그것의 자신의 get-events.php
페이지를 실행하면 내가 (꺼낸 DB 세부 니펫을) 같이 읽을 수있는 GET-events.php의 원본 코드 ...
// Require our Event class and datetime utilities
require dirname(__FILE__) . '/utils.php';
// Short-circuit if the client did not give us a date range.
if (!isset($_GET['start']) || !isset($_GET['end'])) {
die("Please provide a date range.");
}
// Parse the start/end parameters.
// These are assumed to be ISO8601 strings with no time nor timezone, like "2013-12-29".
// Since no timezone will be present, they will parsed as UTC.
$range_start = parseDateTime($_GET['start']);
$range_end = parseDateTime($_GET['end']);
// Parse the timezone parameter if it is present.
$timezone = null;
if (isset($_GET['timezone'])) {
$timezone = new DateTimeZone($_GET['timezone']);
}
class Emp {
public $id = "";
public $title = "";
public $start = "";
public $url = "";
}
while(!$JAN->atEnd()) {
e = new Emp();
$e->id = $JAN->getColumnVal("ID");
$e->title = $JAN->getColumnVal("TITLE");
$e->start = $JAN->getColumnVal("DATE")."T".$JAN->getColumnVal("TIME");
$e->url = "meeting_info.php?ID=".$JAN->getColumnVal("ID");
echo json_encode($e);
$JAN->moveNext();
}
$JAN->moveFirst(); //return RS to first record
// Read and parse our events JSON file into an array of event data arrays.
$json = file_get_contents(dirname(__FILE__) . '/../json/events.json');
$input_arrays = json_decode($json, true);
// Accumulate an output array of event data arrays.
$output_arrays = array();
foreach ($input_arrays as $array) {
// Convert the input array into a useful Event object
$event = new Event($array, $timezone);
// If the event is in-bounds, add it to the output
if ($event->isWithinDayRange($range_start, $range_end)) {
$output_arrays[] = $event->toArray();
}
}
// Send JSON to the client.
echo json_encode($output_arrays);
을 개정 한 난으로 가정하고 무엇을 얻을 올바르게 인코딩 된 JSON은 ... 배열이에, 하나의 예를 반환
{"id":20,"title":"Executive Committee Meeting","start":"2017-05-01T00:00:00","url":"meeting_info.php?ID=20"}
사람이 내가 잘못 한 일을 말해 줄 수 있습니까?
json_encode()는 각각의 PHP 객체가 아닌 완전한 PHP 객체 배열에서 실행해야합니다. 루프에서 각 Emp를 배열에 추가 한 다음 루프가 끝나면 배열을 인코딩합니다. 브라우저의 네트워크 탭에서 AJAX 요청의 결과를 보면, 개별 객체 문자열을 볼 수는 있지만 배열 (사각형) 대괄호로 묶지 않고 쉼표로 구분하지 않는다고 생각합니다. JSON이 유효하지 않음을 나타냅니다. . 잘못된 데이터 형식에 대해서도 콘솔에 오류 메시지가 표시 될 가능성이 있습니다. – ADyson
@ADyson 답으로 추가하십시오! :-) –
@ Don'tPanic 좋은 지적, 나는 정말로, 나는 99 % 확실하다고 대답했다. 끝난! – ADyson