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 incorporate CDN into my webpack build process?

I have developed a module with the following code: export default () => console.log('hello my_module~!') The configuration in the webpack.config.js file looks like this: module.exports = { // ... output: { // ... library: 'he ...

Access Sharepoint from an external site

Looking for assistance with a SharePoint list containing columns for Name, Position, Office, and Salary. Upon logging in with specific credentials to the SharePoint website, I need to retrieve all items from the list and showcase them on my own website. ...

Creating an animated sidebar that moves at a different speed than the rest of the

I have a layout with a large sidebar and small content, where the "Fixed part" refers to sticky positioning. I'm attempting to achieve this using scrollTop, but the sidebar is causing some issues like this: The code should only be executed when the ...

Tips for utilizing global functions in VUE 2 CLI crowd

I have multiple components that require the same functions. Is there a way to avoid duplicating the code in each component and instead use it globally...? Even if I put the function in the App.vue, it still isn't accessible in the components. ...

Learn how to utilize ng2-file-upload in Angular for uploading .ply files effortlessly!

I'm currently working on uploading various files using ng2-file-upload. I've been successful in uploading different file types like png and jpg, but I'm facing an issue with the .ply file extension. Can someone guide me on how to upload a fi ...

Ways to determine the current active tab in React are:

Currently, I am facing an issue with my code involving two tabs. Upon clicking on the second tab, I want to display a specific message. However, I am struggling to determine when the second tab is selected. The main problem lies in the fact that the selec ...

authorization for certain express routes using passport.js

Securing certain express routes with Passport.js authentication Steps for authenticating specific routes in Passport.js Looking for a method to authenticate particular routes using Passport.js Your assistance is greatly appreciated... ...

Issue with jQuery behaving unexpectedly during Ajax requests

Using jQuery/PHP/MySql, I have successfully implemented a feature to load Twitter search results on my page. The initial load is limited to the first 20 search results. As the user scrolls down the page and reaches the bottom, an additional 20 results are ...

"Encountered issues during compiling: X ERROR found at line 9 in the Header.js file, spanning from characters

An error occurred while compiling the module. The following message was displayed: Module not found: Error: Can't resolve '@mui/icons-material/Search' in 'C:\Users\pande\Documents\slack-clone\src\component ...

Exploring the implementation of useMediaQuery within a class component

Utilizing functions as components allows you to harness the power of the useMediaQuery hook from material-ui. However, there seems to be a lack of clear guidance on how to incorporate this hook within a class-based component. After conducting some researc ...

Converting lists to JSON format in a C# web form

Utilizing JSON.stringify, I have implemented textbox autocomplete for a web-form that suggests city names based on user input. The goal is to retrieve relevant city names from the database and display them as suggestions in the autocomplete feature after t ...

Is JavaScript still running despite not displaying insecure items due to IE 8 security warning?

After a user completes a transaction on my site, the confirmation page displays Google conversion tracking code in a small JavaScript snippet. This code is located on my Wordpay callback page, which pulls data from the regular site (HTTP) to the Worldpay s ...

Deciphering the LocalDate and nested object array in an AJAX response

Seeking assistance, looking for solutions to two problems. Firstly, how can I display LocalDate in an ajax response? And secondly, how do I iterate over a list of Custom objects received in the ajax response? I am passing a List of Custom Objects and Loca ...

Highcharts - resolving cross-browser e.Offset discrepancies in mouse event detection on charts

I need to determine if the mouseup event is inside the chart and display the coordinates of the point. The code works in Chrome but not in Firefox due to the lack of the event.offset property. jQuery(chart.container).mouseup(function (event) { eoff ...

Create a complete redirection through Action

Within my ASP.NET MVC 3 application, there is an action triggered by a jQuery AJAX POST request. This action involves validating DB data based on certain attributes. If validation is successful, a PartialView result is returned and added to a div in the vi ...

An error has occurred: sendEmail function is not defined

There seems to be a simple issue here that needs my attention before diving into PHP tasks. I plan on using PHPMailer this time around. I've been attempting to learn how to submit a form on localhost for the past week, and now I'm going to try i ...

NoMethodError: AjaxDatatablesRails module does not have a defined method called `configure`

Whenever I run the rake db:create command, it keeps showing errors like this: ** Invoke db:create (first_time) ** Invoke db:load_config (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! NoMethodError: undefined method ` ...

What is the method for extracting a variable from a URL using JavaScript?

For instance, consider this URL- website.com/page/?var=20 I am looking to extract the "var" variable from the URL using JavaScript. By the way, my actual URL is- https://bipit2.pranaypro21292.repl.co/d21292auth/?code=pimWoHEuV7fgKEVQMTntRnzXqVla3G&gu ...

Enhance a React component by including additional properties when passing it into another component through props

I have a parent element with a dynamically changing height that I need to pass down to its child elements. To get and set the height of the parent element, I am utilizing a ref. The challenge lies in passing this height value from the parent component to ...

Halt the Bootstrap carousel while entering text in a textarea

Is it possible to achieve this? I think so. I have created a carousel with a form inside. The form includes a textarea and a submit button. Currently, the slider does not slide if the mouse pointer is inside it, which is good. However, if the pointer is o ...