Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

javascript - I cannot reach id. events removed in full calendar but not database

I want to remove events that I click on. When I click an event it removes but just from fullcalendar. Then I refresh the page and it comes back. Because it is not removes from database. I tried to access the id but it never works. I cannot reach id. when I write 22 or 23 or any id from database it works but for any id how can I that? there are some questions like that but I research, try but not works at all. It is important now. I will push it to my instructor in 1 hour.

here is my js file

document.addEventListener('DOMContentLoaded', function () {
  var calendarEl = document.getElementById('calendar');
  var calendar = new FullCalendar.Calendar(calendarEl, {
    initialView: 'dayGridMonth',
    selectable: true,
    editable: true,
    eventLimit: true,

    events: "getEvents.php",


    dateClick: function (info) {
      date = info.dateStr;

      var title = prompt("Please enter your event :");


      if (title != null) {
        calendar.addEvent({
          title: title,
          date: date,
          


          allDay: true
        });
        $.ajax({
          url: 'addEvents.php',
          type: "POST",
          data: { title: title, date: date },
          success: function () {

            calendar.fullCalendar('rerenderEvents');
          }
        });

      }
    },

    eventClick: function (events) {
      alert(events.id);
      $.ajax({
        url: "deleteEvents.php",
        type: "POST",
        data: { id:events.id },

        success: function () {

          events.event.remove();
          alert("Deleted Successfully");

        }
      });
    },
  }
  );
  calendar.render();
});



here is my php file

<?php include('dbConnection.php'); 
session_start();
if(!$_SESSION['username']){
    echo "Please login first.";
    ?>
    <a id="loginn" href="GeneralLogin.html" title="generalLogin">Click to login</a>
<?php }

$id = $_POST['id'];


$sql="DELETE FROM events WHERE id=?" ;
$stmt = $conn->prepare($sql);
if ($stmt != false) {
  $stmt->bind_param('i',$id);
$stmt->execute();

}

?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...