What are the reasons behind fullcalendar struggling to interpret JSON data properly?

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

Answer №1

Unfortunately, my solution may not be helpful to others, but here it is.

The issue stemmed from a specific line of JavaScript code in our main file.

  if($('table').length > 0){
         $('table').wrap('<div class="table-scroll"></div>');
    }

This particular line interfered with the HTML output generated by fullcalendar, leading to the failure parsing json error.

Answer №2

Incorporating your code into a PHP page and calling it in FullCalendar like events: '/fullcalendar/json.php' worked flawlessly for me. I'm unsure of what might be causing issues on your end, as it functions perfectly.

<?php
 header('Content-Type: application/json');
 echo json_encode([
   [
    'title' => 'Lorem Ipsum',
    'start' =>  '2019-04-16T13:00:00',
    'end' =>  '2019-04-17T14:00:00'
   ],
   [
    'title' => 'The Test',
    'start' =>  '2019-04-16T10:00:00',
    'end' =>  '2019-04-17T13:00:00'
   ]
]);

However, do check your dates carefully. Your start date is set to 2019 while the end date shows 2018. Additionally, make sure to include time values to visualize the event placements accurately.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on utilizing AngularJS $http for transferring multipart/form-data

In the process of creating a visual interface that interfaces with various REST services (coded in Java), I am encountering an issue when attempting to call one such service: @PUT @Path("serviceName") public Response serviceName(final FormDataMultiPart mu ...

Converting JSON to an object in C# using WebRequest

I am encountering an issue while attempting to convert this JSON into an object of a specific class. The error I receive is: ":" or "{" expected. Below is the JSON in question: {"data":[{"id":"https:\/\/api.cognitive.microsoft.com\/api&bso ...

The toggler in Bootstrap 5's Navbar menu is experiencing difficulties opening on mobile browsers

Just arrived here for the first time. Encountering an issue with my Bootstrap 5.1 Navbar menu. Background info: My website is hosted locally via Xampp with php pages for forms and cookies. Everything functions perfectly on desktop. Checked responsiveness o ...

I'm running into a "timeout" issue with socket.io and a self-signed SSL connection. Can anyone help me troubleshoot this?

After setting up a nodejs server with HTTPS, everything seems to be working fine when sending GET requests. However, I encountered an error message 'WebSocket was closed before the connection was established' when trying to connect another nodejs ...

Is my JQuery width() function giving incorrect value results?

Currently, I am facing a situation similar to the following: We have two popup windows that are quite alike. These popups are generated by a factory in JavaScript, allowing them to share common events and functions. One such function is our custom resize ...

The application encountered an issue: Unable to find a suitable converter for the returned value, which is of the class org.json.JSONObject

I have been working on developing a REST API using the Spring framework. One of the functionalities in my API is to call another API, such as Oracle ORDS. private String processBackground(String object, String url, HttpMethod template) { HttpHead ...

Challenges with rendering text in Three.js

We are currently working on a project in three.js and facing difficulties when it comes to loading fonts onto our text elements. Our approach involves using the TextGeometry object for rendering fonts and the typeface js converter to incorporate new fonts ...

Error in ElectronJS: Trying to access properties that are not defined (specifically 'whenReady')

Below is a straightforward code snippet: function myFunction() { const { app, BrowserWindow } = require('electron') const createWindow = () => { const win = new BrowserWindow({ width: 800, height: 600 ...

Different ways to implement the Vue search select feature in various form structures

I am facing an issue with showing select options of my product in multiple forms. Whenever I choose one option in one form, all the other select forms also change automatically. How can I make each select form unique? Here is what I have tried: My selec ...

Exploring the incorporation of the elasticsearch javascript library within your Aurelia application

Transitioning from the angular realm to aurelia has been a learning experience. However, I've hit a roadblock trying to figure out how to integrate elasticsearch.js into my aurelia app. Does anyone have any tips on how to achieve this? Or perhaps a ...

The Daterangepicker feature is experiencing technical difficulties when implemented on Web Pages using ASP.NET MVC

I'm encountering issues with the daterangepicker script obtained from the adminlte.io template, which isn't working on MVC web pages. Even though it runs fine in PHP, it seems to fail once I switch to asp.net MVC. <html> <head> ...

What is the process for converting/executing TypeScript into JavaScript?

Having trouble running https://github.com/airgram/airgram Encountering this warning message from the post (node:9374) Warning: To load an ES module, set "type": "module" Have already added {"type": "module"} To pa ...

Error encountered in loop for concatenating html elements: identifier unexpectedly found (jquery + html + php)

I am attempting to concatenate HTML inside a variable within a loop and then return it populated. However, I am encountering an error: Uncaught SyntaxError: Unexpected token += in my code. <a style="cursor: pointer" id="addmore">More Entree ?</ ...

Could there be an issue with my website's bootstrap where badges are not being applied properly?

Currently, I am in the process of learning ReactJS and running into an issue where my bootstrap is not working within my .jsx file. Despite following a tutorial (MOSH) diligently and extensively researching on stack overflow, I have not been able to find a ...

JavaScript comparing variables to nested object properties

items resembling this are heading my direction: var info = { a0: { name: 'lengthy title 0', var1_min: '10', var1_max: '99', select: ['alpha', 'gamma'], display: 'value0' }, b12: { ...

Vue watchers capturing original value prior to any updates

When working with Vue.js, we can easily access the value after modification within watchers using the following syntax: watch: function(valueAfterModification){ // ...... } But what about getting the value before it's modified? PS: The official ...

delete the final directory from a file directory

let currentLocation = window.location.pathname; let directory = currentLocation.substring(0, currentLocation.lastIndexOf('/')); The current location is: /examples/html/home/ The directory is: /examples/html/home I am trying to remove the las ...

Encountering the error message: "Error -[__NSArrayM city]: unrecognized selector sent to instance 0x111c03460"

Can someone assist me with using Google's geocoding API to retrieve the city name and geolocation? I am encountering an error in my code and need help identifying where the issue lies. Below is the snippet of my code: ViewController: - (void)search ...

Guide on decrypting a file encrypted with C# using Node JS

I currently have encrypted files in C# using DES and PKCS7 encryption. My objective is to decrypt these files in Node JS. The decryption code in C# that I am using appears like this: public string SSFile_Reader( string fileToDecrypt ) { DESCryptoService ...

IE9 encounters an error when using jQuery's .remove() function

While testing my website in IE9 using Firebug Lite, I encountered an issue. When attempting to run a basic command to remove a div, I received an error saying "TypeError: Object expected". The command I used was: $("#drag-hoverbox_you").remove(); Interes ...