fullcalendar ajax success is not functioning

Currently, I am developing a reservation website using fullcalendar. I am facing an issue where the success function in my Ajax request is not working even though all the data is being successfully inserted into the database. I also tried changing 'success' to 'error', but still no response. Below is the code snippet where I insert an event into the database:

select: function(start, end,  allDay)
        {
         var teacher = prompt("Enter ResourceID");
         if(teacher)
         {
          var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss");
          var end = $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss");
          $.ajax({
           url:"http://show981111.cafe24.com/login-system/addevent.php",
           type:"POST",
           data:{userName: '<?php echo $name; ?>' , newlyBookedDate:start, courseTeacher : teacher, userBranch:'<?php echo $userBranch; ?>', userID: '<?php echo $userID; ?>'},

           success:function()
           {
            calendar.fullCalendar('refetchEvents');
            alert("Added Successfully");
           }
          })
         }
        },

The following is where I retrieve the PHP variables used in the above code:

<?php

session_start();


if ( $_SESSION['logged_in'] != 1 ) {
  $_SESSION['message'] = "You must log in before viewing your profile page!";
  header("location: error.php");    
}
else {
    // Makes it easier to read
    $name = $_SESSION['userName'];
    $userBranch = $_SESSION['userBranch'];
    $userID = $_SESSION['userID'];


}

?>

The below code snippet pertains to addevent.php:

<?php

// Values received via ajax
$userName = $_POST['userName'];
$newlyBookedDate = $_POST['newlyBookedDate'];
$courseTeacher = $_POST['courseTeacher'];
$userBranch = $_POST['userBranch'];
$userID = $_POST['userID'];
// connection to the database
try {
$bdd = new PDO('mysql:host=localhost;dbname=show981111', 'show981111', 'pass');
} catch(Exception $e) {
exit('Unable to connect to database.');
}

// insert the records
$sql = "INSERT INTO DAYSCHEDULE (newlyBookedDate, userID, userName, courseTeacher,userBranch ) VALUES (:newlyBookedDate, :userID, :userName, :courseTeacher, :userBranch)";
$q = $bdd->prepare($sql);
$q->execute(array(':newlyBookedDate'=>$newlyBookedDate, ':userID'=>$userID, ':userName'=>$userName,  ':courseTeacher'=>$courseTeacher,':userBranch'=>$userBranch ));

?>

Answer №1

After inserting your data into the database, retrieve the response from your controller/W and check the log for any feedback.

$.ajax({
           url:"http://show981111.cafe24.com/login-system/addevent.php",
           type:"POST",
           data:{userName: '<?php echo $name; ?>' , newlyBookedDate:start, courseTeacher : teacher, userBranch:'<?php echo $userBranch; ?>', userID: '<?php echo $userID; ?>'},

           success:function(response)
           {
            console.log(response);
            calendar.fullCalendar('refetchEvents');
            alert("Added Successfully");
           }
          });

If you do not encounter any errors, modify the success function as follows:

success:function(response)
           {
            console.log(response);
            //calendar.fullCalendar('refetchEvents');
            //if calendar is used as an id then 
            $("#calendar").fullCalendar('refetchEvents');
            //or it is a class then
            $(".calendar").fullCalendar('refetchEvents');
            alert("Added Successfully");
           }

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

Rerendering of a React component occurs upon a change in its state

Previously, my form was functioning flawlessly. However, after making a few modifications to the state variables, the input field now loses focus upon a state change. I am utilizing MUI and everything was working perfectly until this sudden issue arose f ...

Disabling the submit button after submitting the form results in the page failing to load

I am encountering an issue with my HTML form that submits to another page via POST. After the form validates, I attempt to disable or hide the submit button to prevent double submission and inform the user that the next page may take some time to load. He ...

How can I create a JSON output from my MySQL database that includes the total count of records per day for a Task entry?

I am looking to implement the JavaScript library called Cal-Heatmap (https://kamisama.github.io/cal-heatmap/) to create an Event style heatmap similar to GitHub's. The objective is to visualize the number of actions taken on each Task record in my Pr ...

Refreshing an AJAX request

In my Cordova application, I have implemented an AJAX call. Before making the actual call, I check for internet connectivity. However, sometimes there is a momentary loss of internet connection on mobile devices after the call is initiated, resulting in th ...

The most effective method for calculating overhead is through the utilization of synchronous techniques

I'm currently developing a nodeJS app that heavily relies on synchronous methods, particularly for file operations and spawning child processes. I am looking to assess the impact of these blocking main thread activities in terms of overhead. What woul ...

Differences in results between using .length with jQuery selectors and vanilla JS selectors

Examining the code snippet below from an HTML page: <form> <select id="select"> <option></option> <option></option> <option></option> </select> </form> When using ...

Comparison between Static and Dynamic SVG

I have noticed a significant contrast in the rendering of static versus dynamic SVG. Take a look at this code snippet: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=devi ...

Learn how to configure and utilize an AngularJS factory using ngResource along with passing parameters in the call

As a newcomer to Angular, I'm seeking guidance on creating a new factory utilizing ngResource instead of $http, with the ability to pass parameters. Following an example provided here, I have defined my factory as shown below: app.factory('abst ...

What is the best way to organize mocha tests to run sequentially?

I am currently working with a group of modules that are triggered by a global event emitter. These modules operate in a sequential chain based on specific events, such as: boot.ready server created (triggered by boot.ready event) server configured (trigg ...

What is the best way to disable the click function for <a> tags that have a specific class?

I am dealing with parent navigation items that have children, and I want to prevent the parent items from being clickable. Here is an example of how they currently look: <a href="parent">Parent Item</a> Is there a way to select the <a> ...

What is the best way to include an Observable in this function?

Every time I send a set of credentials to my API and receive the data that needs to be stored, I encounter an error during the login process. Error: TypeError: You have provided an invalid object when a stream was expected. You can provide an Observable ...

The outcomes of JSON.stringify and JSON.parse can vary

I am facing an issue with using JSON.stringify to create a JSON string from an Object. After saving the string into a file, I attempt to read the file and use JSON.parse to retrieve the object again. However, it seems that the process is not working as exp ...

Unable to retrieve innerHTML from a jQuery element

My current task involves implementing the Google Maps API. The code snippet below is what I have written so far: <div id="map"></div> To inspect the content of $("div#map"), I am utilizing the Google Chrome console. console.log($("div#map")) ...

Encountering a 400 Error and CORS problem with Magento 2 Token Authentication

When I use token authentication in my app to access the magento API, everything works fine with postman. However, when I try to implement it using jQuery post, I consistently receive a 400 error due to lack of support for the HTTP verb OPTIONS for prefligh ...

Traversing an array of objects in TypeScript and appending to a separate array if not already present

I have been given an array containing objects in the following format: export interface Part { workOrder?: string; task?: string; partNumber?: string; qty?: number; image?: string; name?: string; } My goal is to loop through each object in th ...

Having more than one controller for a single view in AngularJS

Is it possible to use multiple controllers for a single URL view in AngularJS? I am having trouble finding documentation on this. I want to have a controller that switches the page header title on all pages, but some pages already have a controller. app.j ...

I'm encountering an issue where it appears that my ajax method may not be effectively communicating with my webservice

I am currently working on calling a webservice using an ajax request with the intention of retrieving clinical cases within a specific date range (for example, between 2015-01-01 and 2016-06-08). The webservice functions perfectly when tested individually. ...

Interactive form components. Utilizing JavaScript to dynamically update existing values

I have a form that allows users to generate multiple form elements, such as repeat select boxes, dynamically. The relevant code snippet of the form in question is provided below: for ($i=0; $i < $number; $i++) { <labe ...

Bootstrap is causing issues with unidentified div elements

I recently embarked on creating a slideshow using HTML, CSS, and jQuery. After completing the slideshow, I decided to add an interactive page beneath it. To streamline the layout process, I opted to utilize Bootstrap. However, upon loading Bootstrap, I en ...

Utilizing Puppeteer to Navigate and Interact with Elements Sharing Identical Class Names

I am new to Puppeteer and NodeJs, and I am attempting to scrape a specific website with multiple posts that contain a List element. Clicking on the List element loads the comment section. My question is: I want to click on all the list elements (since th ...