Unable to refresh the fullcalendar section following an ajax post click

Currently developing a calendar using fullcalendar.

I have created an ajax button that retrieves events from another php page.

The first click on the ajax button works fine, displaying a nice month calendar with events. However, my issue arises when I click the button a second time - the calendar does not reload or render again, leaving me stuck with the initial calendar which is no longer relevant to me.

Does anyone know what the problem might be and how I can ensure that a new calendar is published every time the ajax button is clicked?

Here is the code snippet:

<form id="my-form-id" method="post" action="Calendar_form3.php"> Year:
    <INPUT NAME="gregorian_year" SIZE=4 MAXLENGTH=4 value="2016">(1-6000) Latitude:
    <INPUT NAME="latitude" value="40.7127"> Longitude:
    <INPUT NAME="longitude" value="-74.0059"> <button id="ajax-button" type="button">Ajax button</button> </form>
<script>
    function displayCalendar() {
        var target = document.getElementById("main");
        var formData = new FormData(document.getElementById("my-form-id"));
        console.log(formData);
        var xhr = new XMLHttpRequest();
        xhr.open('post', 'JewishCalendar_form3.php', true);
        xhr.onreadystatechange = function() {
            console.log('readyState: ' + xhr.readyState);
            if (xhr.readyState == 2) {
                target.innerHTML = 'Loading...';
            }
            if (xhr.readyState == 4 && xhr.status == 200) {
                var Month_details_for_display = JSON.parse(xhr.responseText);
                //var Month_details_for_display= JSON.parse(Month_details_for_display2);
                target.innerHTML = "funciton will start working...";
                displayCalendar222(Month_details_for_display);
            }
        }
        xhr.send(formData);
    }

    function displayCalendar222(Month_details_for_display) {
        alert("Hello! I am an alert box!!");
        var Events_In_Json = Month_details_for_display['EventsInSameStractureForAll'];
        var json_backgrundColor = Month_details_for_display['Big_Calendar_cell_background_color'];
        var json_iconstring = Month_details_for_display['iconString'];
        var DefaulteDateForFullCalendarISO8601 = Month_details_for_display['fullMonthDetails']['DefaulteDateForFullCalendarISO8601'];
        $('#calendar').fullCalendar({
            header: {
                left: 'prev',
                center: 'title',
                right: 'next'
            },
            events: Events_In_Json,
            fixedWeekCount: false,
            defaultDate: DefaulteDateForFullCalendarISO8601,
            dayRender: function(date, cell) {
                var cellDate = date.format('D');
                if (!cell.hasClass('fc-other-month')) {
                    cell.css('background-color', json_backgrundColor[cellDate]);
                    if (json_iconstring[cellDate].includes('HAV')) {
                        cell.prepend('<img src=\' icons/havdala2.png \'>');
                    }
                    // More icon conditions go here...
                    
                } else {
                    cell.css('background-color', '#ffffff');
                }
            },
        });
    }
    var button = document.getElementById("ajax-button");
    button.addEventListener("click", displayCalendar);
</script>
<div id='main'> result here </div>
<div id='calendar'></div>

Answer №1

When you click the button for the second time, you can choose to either re-render the calendar by using this code:

$('#calendar').fullCalendar('render');

Or you can completely remove and recreate the calendar before rendering it again with this code:

$('#calendar').fullCalendar('destroy')
              .empty()
              .fullCalendar({
                 //...
              });

For more information, you can visit:

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

What is the best way to insert an image between two sections using CSS?

As I work on a new webpage, I find myself stuck (yes, I'm a beginner :-) ). I have a header followed by a section, and I would like to place images in between the two. However, despite my attempts to position the images, they keep getting hidden "und ...

Setting the select option in AngularJS with predefined options can be easily achieved with

I am encountering an issue with a select element that has predefined options. Even though the select element is using ng-model, when the model is set to one of the option values, it fails to be selected. Below is the snippet of HTML code: <select clas ...

The website is unresponsive to the media query

Currently, I am working on a project using Windows 10, Codeigniter, jQuery, and Firefox 43.0.4. However, I am facing an issue that is quite baffling to me. My goal is to apply styles specifically for an iPad-sized window, so I have implemented the followin ...

Filtering and displaying results with Django and Ajax: A step-by-step guide

I have been working on filtering and displaying data in Django based on user selections from a drop-down box. I am utilizing an Ajax call to send a request to Django views, where the filtering of data takes place. For example, when a user selects "Airline ...

Error message: "Property undefined when Angular attempts to call a function from jQuery/JavaScript."

I'm currently attempting to invoke an angular controller from my JavaScript code. This is my first encounter with Angular and I must admit, I'm feeling a bit overwhelmed! I've been following this example: Unfortunately, when testing it out ...

"Exploring the Relationship Between Parent and Child Elements in CSS

Is it possible for an id to act as a parent in CSS? For instance: <div id="link"> <a href="www.example.com"></a> </div> The CSS code: #link > a{ /* style would be applied here*/ } Can this actually be achieved? ...

Guide to establishing multiple relationships using the `belongsTo` method within a Loopback model

In my database, I have three models named "Companies," "Employees," and "Employments." The "Employments" model is set up to have a belongsTo relationship with both a company and an employee. Inversely, every "Employee" should have a hasOne relationship wit ...

What is the size restriction when utilizing the "headers" attribute of the jQuery.ajax technique?

What is the size limit for the "headers" property of the jQuery.ajax method? For example: $.ajax({ type: 'POST', url: 'submit.php', headers: { 'CUSTOM_DATA': someBigString },// Is there a limit for "someBigString ...

Leveraging RXJS for efficient data retrieval in nodejs

When dealing with sending a bulk of data and moving on to the next one upon completion, it can be quite challenging. Take for instance this function: async function test() { await sample.sampleStructure() await sample.sampleDataAdd() await sample.sa ...

Creating a stunning horizontal bar chart with the react-d3-components framework

I am currently implementing a D3 chart using the react-d3-components library. So far, I have successfully generated a vertical bar chart. However, my specific requirement is to create a horizontal bar chart. import React from 'react'; import Reac ...

JavaScript enables the deletion of a class

In HTML 2, I am able to show different statements based on the scenario. These statements are styled using the Bootstrap alert class. The goal is to ensure that when new data is sent, any old communication disappears without causing overload on the page. ...

An issue with the JSON format encountered in the D3 pack layout

I am completely new to d3 and have only been learning it for the past 3 days. I attempted to create a pack layout, but I encountered an issue where I couldn't call the translate (or transform) function based on the data in an external json file. The s ...

Experiencing the 'Page prerendering error' message within Next.js

I encountered a prerender error during the deployment phase that I'm struggling to comprehend: Error occurred prerendering page "/about". Read more: https://nextjs.org/docs/messages/prerender-error ⨯ useSearchParams() should be wrapped in ...

utilizing object methods to retrieve object attributes

I am currently working on developing a new application named myApp. This application includes a property called regularNameErrors and a method called populateJSON. The populateJSON method utilizes an AJAX call to retrieve a JSON object, which is then added ...

Navigate to the top of the page using jQuery

Attempting to implement a simple "scroll jump to target" functionality. I've managed to set it up for all parts except the "scroll to top". The jumping works based on the tag's id, so it navigates well everywhere else, but not to the very top. He ...

Acquire JSON information in the form of an IEnumerable

Purpose: Issue: When transmitting JSON data from the frontend to the backend, it is not being received as an IEnumerable. Which part of the code needs adjustment? Details: * Frontend using JQuery * Backend using Asp.net MVC Thank you! @{ ViewD ...

After triggering an action, I am eager to make a selection from the store

To accomplish my task, I must first select from the store and verify if there is no data available. If no data is found, I need to dispatch an action and then re-select from the store once again. Here is the code snippet that I am currently using: t ...

Combining PHP and HTML: Utilizing nested foreach loops with interspersed HTML code

Attempting to create a layout of items using an Accordion arrangement (from Bootstrap) has led me to retrieve data from a pgsql db. Fortunately, the data retrieval process is successful. The challenge lies in displaying this data, as I am encountering an ...

Concentrate on Selecting Multiple Cells in ag-Grid (Similar to Excel's Click and Drag Feature)

Is there a way to click and drag the mouse to adjust the size of the focus box around specific cells in ag-Grid? This feature is very handy in Excel and I was wondering if it is available in ag-Grid or if there is a workaround. Any insights would be apprec ...

The challenge of aligning widgets in bootstrap panels across different browsers

Incorporating angularjs and bootstrap3, I'm in search of the best way to center widgets within a panel and achieve responsive behavior. Interestingly, the results vary across browsers, particularly in Firefox. Within my code, I have 4 column divs str ...