Having trouble loading events on Fullcalendar.io?

Our team is utilizing fullcalendar.io and aiming to retrieve an event from our API controller.

The Controller

[Route("api/Bookings")]
public class BookingApiController
{

    // GET
    [HttpGet]
    public string Get()                   
    {

        var returnJson = new
        {
            events = new[]
            {
                new {title = "bro", start = "2018-05-06"},
                new {title = "bro2", start = "2018-05-05"}
            }
        };
        return JsonConvert.SerializeObject(returnJson);

    }
}

Our javascript file

 $ ( function () {
    
    $('# calendar '). fullCalendar({
        // weekends: false
        
        dayClick: function ( date ) {
            
            window.location.href = "/Booking/Booking? selectedDate =" + date.format ();
        },
        
        eventSources: [
            {
                url: '/ api / Booking',
                color: 'yellow', // a option!
                textColor: 'black' // a option!
            }
        ]
        
    })
});
 

However, the JavaScript script fails to receive the event correctly. Although it does obtain the JSON data, it doesn't add the event accurately to the calendar.

Answer №1

When observing the ajax request in your browser tools, what does the final returned JSON resemble?

fullCalendar is looking for a simple array of events, but it seems that you are returning them nested within another object. As a result, fullCalendar may not recognize these events and will assume there are no events to display.

You might be receiving something along these lines:

{
  events: [ 
    //...array of events
  ]
}

Instead, you should provide a structure like this:

[
    //...array of events
]

Although untested, the following code snippet should resolve the issue:

[HttpGet]
public string Get()                   
{
    var events = new[]
    {
        new {title = "bro", start = "2018-05-06"},
        new {title = "bro2", start = "2018-05-05"}
    };

    return JsonConvert.SerializeObject(events);
}

Note the absence of the outer "returnJson" object in this version.

For information on the event feed system being utilized, refer to https://fullcalendar.io/docs/events-json-feed. You can also check out https://fullcalendar.io/docs/events-array for an example of the required object format for creating a valid list of events.

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

Waiting for all API queries in VueJS is important to ensure that all data has been

Hey there, I currently have an API set up using Django Rest Framework and the front end is built with VueJS. I have a form view that can either be used to Add New or Modify existing data. The structure of the form remains the same, but it checks if an ID ...

Guide to fetching a phone number from MySQL in Android using JSON

When a user logs in, I am retrieving details (first name, email, bike number, mobile number) from a MySQL database using JSON. However, all details are being retrieved except for the mobile number. This is my code: progressBar = new ProgressDialog(v.getC ...

Using React to easily rearrange images by dragging and dropping them

Currently, I am working on incorporating drag-and-drop functionality using React JS along with the react-dropzone library to display thumbnails. The code implementation is provided below: import React from "react"; import ReactDOM from "react-dom"; impor ...

There was a TypeError encountered in a Node application, stating: "Unable to access the 'trim' property of an undefined

Currently, I am developing a JavaScript application that follows the MVC model. In the controllers, there is a userController.js file, and in the models, there is a user.js file which contains a cleanup function. However, I am encountering a TypeError: Can ...

Having trouble getting ngAnimate to work properly?

I am facing an issue with ngAnimate dependency injection. For some reason, whenever I add ngAnimate as a dependency in my JavaScript code, it does not seem to work. It's definitely not the script... Here is the HTML code snippet: <!doctype html& ...

Creating a radial progress chart using Plotly JavaScript

I recently started working with the Plotly library and now I need to display a circular progress graph in Vuejs 2, like the one shown below. While Plotly is a comprehensive tool, I have not come across an example that matches this specific design using Ja ...

What is the best way to set up a server in React using Express or HTTP?

I am currently in the process of developing a web application using react js. In order to create a server for my client within the project, I have decided to utilize either express or http. Here is the code snippet that I attempted: import React from " ...

Support for Big Decimal in Org.json

Is there a way to add BigDecimal support to the org.json library? I'm attempting XML to JSON conversion using this library, but it seems to be lacking Big Decimal support. Any suggestions on how to handle this issue? Even after trying the 20200518 ve ...

When I click, I expect to retrieve the tr element, but instead, I am receiving the td element

When I have a table and click on a tr element, the function returns a td element instead. Can someone explain why this is happening? let func = function () { $("tr").on("click", (event) => { event.preventDefault(); event.stopPropaga ...

Error encountered while returning JSON from a RESTful API in Quarkus due to LazyInitializationException

I'm currently working on developing a straightforward Quarkus application. My project involves two entity classes that have a one-to-many relationship: @Entity public class Person extends PanacheEntity { public String name; public LocalDate ...

Unlocking JSON with various structures using Swift

I am dealing with json data that follows a consistent structure from a nosql database (PK, SK, attributes). The content of the attributes section varies depending on the value of SK. For instance: [ { "PK": "POLL#1544693DF0E88EC-3225- ...

What steps should I follow to obtain the return value after invoking these functions?

I have a task that requires creating a nodejs script for two specific functions: Retrieve my public IP address. Update my public IP address on my freenom.com account for a registered domain. Currently, I have two separate scripts in place to accompl ...

Understanding how to use the 'this' variable in Vue components is essential for efficiently modifying DOM elements. Let's dive into a clarification on the usage of 'this'

Within my vue component, the structure is as follows: export default{ name: '', data: function () { return { var1 :{}, var2 : {}, ... } }, created: function () { this.methodName1() }, methods: { me ...

Action of Submit Button Based on Field Matching Another Form

I currently have a single page that contains two forms, with only one form being displayed at the moment. The concept is that if the user selects a specific state from the drop-down menu and clicks on the submit button, they will be redirected to either a ...

What are the best practices for securely using JSON.stringify in JavaScript?

When I use JSON.stringify on a string that includes <script> tags, the script tags somehow escape and show up in the body of my document, causing unexpected results with the "injected" data. I'm puzzled by how they manage to escape, considering ...

What is the correct way to format a Json content type?

To extract only the operation content of the provided JSON, follow these steps: {"entries":[{"description":"Text transform on 101 cells in column Column 2: value.toLowercase()","operation":{"op":"core/ ...

Fetching dynamic JavaScript generated by PHP

I am creating a lightweight website and I have a piece of javascript code that I want to convert into a module by putting it in a separate file. This way, the code will only be loaded after a specific onClick event occurs. Successfully loading the javascr ...

Interpreting JSON outcomes in C#

Any help is greatly appreciated! I'm currently working on parsing a Json response from an API, but I find the data structure to be challenging to understand. The response seems to consist of a 'header' followed by multiple items (see the r ...

Shifting the position of personalized tabs using Jquery

I have created some basic HTML/CSS tabs and I want to move to the next tab by clicking a link at the bottom of every tab. HTML <ul class="tabs"> <li class="active"> <a href="#">Explainer (2mins)</a> <div class=" ...

Converting Persian calendar date to Gregorian in JavaScript

Looking for assistance in converting a date from 1379/10/02 to AD format, specifically to the date 2000/4/29 using the momentJs library. Any help with this task would be greatly appreciated. Thank you! ...