fullcalendar ajax成功不起作用

时间:2018-07-01 10:25:37

标签: javascript ajax fullcalendar

我正在使用全日历预订网站。我使用Ajax将事件插入数据库。但是,问题在于成功功能无法正常工作,但是每个数据都已成功插入到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");
           }
          })
         }
        },

这是我上面使用的php变量的地方

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


}

?>

这是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 个答案:

答案 0 :(得分:1)

如果将数据插入数据库,则将控制器/ W对成功函数参数的响应作为参数,并查看日志。

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

如果没有错误,则成功函数应该为

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