Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...