fullcalendar ajax success does not working


fullcalendar ajax success does not working



I am making reservation website using fullcalendar. I insert event into my DB using Ajax. However, the problem is that success function was not working, but every data was successfully inserted into DB. Also I changed success to error, but still nothing happened.
Here is code where I insert event into DB


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");
}
})
}
},



Here is where I get the php variables that I use above


<?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'];


}



?>



This is code for 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 ));



?>




1 Answer
1



if your data inserted into DB then take the response from your controller/W to the success function parameter and see the log.


$.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 are getting no error then in the success function should be


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");
}





still alert does not appear, even if all the data is inserted.
– yongseung
Jul 1 at 11:59





did you see any response in the console? "calendar" is class or id?? please choose one between them from the success function.
– Shakil Ahammed
Jul 1 at 12:15





Wow it worked! I choose one that calendar is used as an id. Thank you!
– yongseung
Jul 2 at 3:53







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?