首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >完整日历ajax成功不起作用

完整日历ajax成功不起作用
EN

Stack Overflow用户
提问于 2018-07-01 18:25:37
回答 1查看 268关注 0票数 0

我正在使用全日程表进行预订网站。我使用Ajax将事件插入到数据库中。然而,问题是成功函数没有工作,但每个数据都成功地插入到数据库中。此外,我将成功更改为错误,但仍然没有发生任何事情。下面是将事件插入到DB中的代码

代码语言:javascript
复制
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变量的地方

代码语言:javascript
复制
<?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的代码

代码语言:javascript
复制
<?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 ));

?>

EN

回答 1

Stack Overflow用户

发布于 2018-07-01 19:32:30

如果您的数据插入到DB中,则从控制器/W获取对success函数参数的响应并查看日志。

代码语言:javascript
复制
$.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");
           }
          });

如果你没有得到错误,那么在成功函数中应该是

代码语言:javascript
复制
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");
           }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51122442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档