Issue Overview
I have configured fullcalendar and I'm attempting to display data using the JSON event source as outlined in their documentation here.
However, every time I try to load the data, I receive an error message saying Failure parsing JSON
.
Steps Taken So Far
The JSON content causing the failure is:
[{"title":"Lorem Ipsum","start":"2019-04-01","end":"2019-04-02"},{"title":"The Test","start":"2018-09-01","end":"2018-09-02"}]
I am currently working with fullcalendar version 4.0.2.
I have verified the JSON output from my PHP code through a linter.
Added Content-Type: application/json
header to the JSON response.
Attempted to use the eventDataTransform
hook by referencing sample JSON provided in the fullcalendar docs here (details can be found in edit history)
~~Interestingly, directly placing the above JSON within the javascript in the events
option does work.~~ EDIT: As pointed out by Jaromanda X and Quentin, this is an array in JavaScript format and not valid JSON.
Code Snippet
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'dayGrid' ],
defaultView: 'dayGridMonth',
locale: 'nl',
events: '/fullcalendar/json.php'
});
I expect that the JSON should parse correctly since the response is similar to what I provide directly to the events
option.
Extra Details
Snippet of the json.php file contents
<?php
header('Content-Type: application/json');
echo json_encode([
[
'title' => 'Lorem Ipsum',
'start' => '2019-04-01',
'end' => '2018-04-02'
],
[
'title' => 'The Test',
'start' => '2018-09-01',
'end' => '2018-09-02'
]
]);exit;
Changing the method to GET did not resolve the issue.
I've included a screenshot of the network tab response from the inspector for review JSON response in inspector