What is the best way to manage a JSON feed that does not provide any results?

Excuse my lack of experience as I pose my first question. Using FullCalendar 5.10.1, I am working on retrieving events dynamically associated with Festivals.

I have followed the 'events (as a json feed)' pattern from the documentation. When there is at least one event linked to the selected Festival, everything works smoothly and the calendar displays the event(s) correctly.

However, if the feed does not locate any events associated with the Festival selection, the failure callback triggers immediately. An error message 'Failure parsing JSON' appears in the Console. Dismissing the failure message loads an empty calendar as expected.

It's evident that I haven't properly handled the scenario where no events are found, but I'm unsure whether this should be addressed in the feed SQL or within the FullCalendar code.

This setup is running inside a Bootstrap tab. Some temporary code is included here to address a conflict issue with a vendor's theme by delaying the calendar load after setting a variable to the id of the calendar tab.

Admittedly, I may not have presented the code optimally here and possibly did not explain the issue thoroughly enough. Any guidance for this beginner would be greatly appreciated.

<script type="text/javascript">

  document.addEventListener('DOMContentLoaded', function() {
    var calendarButton = document.getElementById('calendarButton');
    var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {

      themeSystem: 'bootstrap',
      headerToolbar: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth,timeGridWeek,timeGridDay'
      },
      weekNumberCalculation: "ISO",
      initialView: 'dayGridMonth',
      initialDate: '2021-07-01',
      eventDidMount: function(info) {
        $(info.el).tooltip({
          title: info.event.extendedProps.description,
          placement: 'top',
          trigger: 'hover',
          container: 'body'
        });
      },
      eventSources: [
        {
          url: '/DesktopModules/XModPro/Feed.aspx',
          method: 'POST',
          datatype: 'JSON',
          extraParams: {
            pid: '0',
            xfd: 'Events_FullCalendar_FestivalID',
            FestivalID: '[[FestivalID]]'
          },
          failure: function() {
            alert('There was an error while fetching events!');
          },

          color: '#a1a535',   // a non-ajax option
          textColor: 'white' // a non-ajax option
        }
      ]
    });

    calendarButton.addEventListener('click', e => {
      setTimeout(() => {calendar.render()}, 1);
    });
  });
</script>

Feed SQL

<%@ Control Language="vb" AutoEventWireup="false" Inherits="KnowBetter.XModPro.FeedBase" %>
<%@ Register Assembly="KnowBetter.XModPro.Web.Controls" Namespace="KnowBetter.XModPro.Web.Controls" TagPrefix="xmod" %>
<xmod:masterview runat="server">
<xmod:JsonFeed runat="server">              
 
<ListDataSource CommandText="SELECT
                             EventID AS 'id',
                             VenueID AS 'vid',
                             FestivalID,
                             EventTitle AS 'title',
                             EventDescription AS 'description',
                             EventStartTime AS 'start',
                             EventEndTime AS 'end'

                            FROM la360_Event
                            WHERE FestivalID = @FestivalID">

<Parameter Name = "FestivalID" value= '<%#FormData("FestivalID")%>' DataType="string" />
</ListDataSource>

</xmod:JsonFeed></xmod:masterview>

Answer №1

I wanted to share my 'solution' here for anyone who may benefit from it in the future. By using UNION, I was able to insert a null event record into the feed result. This ensures that FullCalendar continues to function even when there are no actual events. While my syntax may not be the most elegant or well-written, both FullCalendar and I are pleased with the outcome.

<ListDataSource CommandText="SELECT
                         null AS 'id',
                         null AS 'vid',
                         null AS 'FestivalID',
                         null AS 'title',
                         null AS 'description',
                         null AS 'start',
                         null AS 'end'
                         
                         UNION
                                               
                         SELECT
                         EventID AS 'id',
                         VenueID AS 'vid',
                         FestivalID,
                         EventTitle AS 'title',
                         EventDescription AS 'description',
                         EventStartTime AS 'start',
                         EventEndTime AS 'end'

                         FROM la360_Event
                         WHERE FestivalID = @FestivalID">

                        <Parameter Name = "FestivalID" value= '[[Form:FestivalID]]' DataType="int32"/>

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

jQuery Refuses to Perform Animation

I'm facing an issue with animating a specific element using jQuery while scrolling down the page. My goal is to change the background color of the element from transparent to black, but so far, my attempts have been unsuccessful. Can someone please pr ...

Traversing an array of numerical values to find a particular ID in an SQL database

My current challenge involves splitting an array of integers and then assigning each item to a specific id DECLARE @position INT DECLARE @arrayList varchar(8000) DECLARE @len INT DECLARE @value varchar(8000) SET @arrayList = '1,2,3,4,5' IF @arr ...

What could be causing my ajax request to not be successfully compiled?

I seem to be experiencing an issue with this part of my code. Despite trying multiple methods, it still isn't functioning correctly. What steps can I take to resolve this problem? $.ajax({ url: "https://corona-api.com/countries/BR", ...

What is the best way to transfer a content script variable to a background script in a Chrome Extension?

I am looking to transfer a variable named "website_hostname" from the content script to the background script. This variable holds the hostname of the website you are currently visiting. Content Script: var website_hostname = window.location.href; //Cod ...

Navigating through an object using both dot and bracket notation

Can anyone shed some light on why I keep getting an 'undefined' message when trying to access object properties using dot notation like return contacts[i].prop;? However, if I use bracket notation like return contacts[i][prop];, it works fine an ...

When the add button is clicked, I would like to implement a feature where a checkbox is added

When the user clicks on the link "출력하기", I want the web page to add a checkbox to all images. I wrote this code, but it's not working. Can anyone help me? This is my JS: $(document).ready(function(){ $("#print").on('click', fu ...

Manipulate a value using JavaScript

While the intention is for the button value to switch between 1 and 0, the echo $_POST["ordina"] consistently returns 1. Despite checking the code multiple times, I am unable to identify the issue. <script> function order() { if (document.ordination ...

Using Python with Selenium and JavaScript for Logging in

When using Selenium and Python, I am attempting to log in to a website but encountering difficulties. The issue is that the source code does not display the necessary Id=apple_Id required for sending login information, although it can be seen when inspecti ...

The scale configuration for scale: x is not valid for creating a time scale chart using chart.js

I am currently utilizing VueJS and attempting to integrate a time scale chart using Chart.js. However, I encountered the following error: Invalid scale configuration for scale: x Below is my configuration : First, I have a component named Chart.vue with ...

Tips for repairing a button using a JavaScript function in an HTML document

I am currently working on extracting titles from body text. To achieve this, I have created a button and linked my function to it. The issue I am facing is that when I click on the button, it disappears from its original position. I intend to keep it in pl ...

Session cookies in Cordova do not function properly on devices running the Android Lollipop operating system

I recently created a mobile app using Cordova/Phonegap for Android that relies on session cookies to authenticate users with third party websites. The app sends an AJAX post request (using jQuery) and the cookies are automatically set. However, after upda ...

Is there a way to integrate the javascript and jQuery functions in order to conceal a button?

I recently acquired the File Upload script known as Simple Photo Manager and I am looking to incorporate jQuery functions with the existing JS code in the script. My main goal is to make the Delete button disappear once it has been clicked. However, I am ...

Identifying whether a webpage has integrated Google Analytics

I am working with a node server. I provide a Url in the request and utilize cherio to extract the contents. My current goal is to identify whether the webpage uses Google Analytics. How can I achieve this? request({uri: URL}, function(error, response, bod ...

Loop proceeding without waiting for promise resolution containing nested Firebase call

I am currently facing an issue with making Firebase database calls within a loop and an outer Firebase call. The inner database call utilizes data returned from the outer call and the loop, hence it is nested inside the outer one. The goal is to set the re ...

Mastering the usage of AngularJS Directive controllerAs syntax with scope is key to developing

I have included my code below: // HTML <body> <h1>{{foo.name}}</h1> <my-directive></my-directive> </body> // Scripts app.directive('myDirective', function() { return { restrict: 'E', ...

Animating jQuery to adjust height based on a percentage

My animation using percentage is not working as expected. It expands to the whole height instantly instead of smoothly transitioning to 100%. Here is my CSS code: #block-views{ overflow:hidden; height:20px; } This is my HTML code: <div id="block-view ...

Are you experiencing issues with the map displaying inaccurate latitude and longitude when clicking on a specific point?

I've successfully created a simple polyline on Google Maps and attached a click event listener to it. However, I'm encountering an issue where clicking on the line provides me with latitude and longitude coordinates that point to Canada, even th ...

Creating an enum from an associative array for restructuring conditions

Hey everyone, I have a situation where my current condition is working fine, but now I need to convert it into an enum. Unfortunately, the enum doesn't seem to work with my existing condition as mentioned by the team lead. Currently, my condition loo ...

Utilizing MVC with Ajax-enhanced Models within a Razor view

What I want to achieve is to make my MVC 5 application dynamic in accepting surveys from users. The EF models inherited by me are structured like this: Survey Questions Answers The task given to me is to add a NestedSurveyId to the Answer object, so t ...

How can I achieve the functionality of an image changing when clicked and going back to its original state upon release with the help of HTML

I am facing an issue with styling an element to look like a button and function as a clickable link. My goal is to create a visual effect of a pressed button when it is clicked, while also loading the target page. For reference, here is a (non-working) J ...