Fullcalendar remove Ajax/PHP event

Asked

Viewed 66 times

1

I am trying to use the removeEvent method in my calendar and send data in ajax to delete the event from my database.

    eventClick: function (calEvent, jsEvent, view) {
    $.ajax({
       url: 'calendar/remove_event.php',
       data: 'id=' + event.id,
       type: "POST",
       success: function () {
          $('#calendar').fullCalendar('removeEvents', calEvent._id);
       }
   });
},

and PHP:

    $id = $_POST['id'];

$ligacao = mysqli_connect("localhost", "root", "", "mydatabase");
if (mysqli_connect_errno()) {
    echo "Can't connect to database: " . mysqli_connect_error();
}

$sql = "delete from events WHERE id= '$id'";
$resultado = mysqli_query($ligacao, $sql);
mysqli_close($ligacao);

When I click on the event, it is removed from the calendar, but if I refresh the page it is there again because it has not been removed from the database. Here is the documentation for these methods (removeEvent and eventClick):

http://fullcalendar.io/docs/mouse/eventClick/

http://fullcalendar.io/docs/event_data/removeEvents/

The id variable is used in other places successfully for example the eventDrop where I take the event and drop over another date, updating the database of the new dates for the respective event:

eventDrop: function (event, delta) {
                            start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
                            end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
                            $.ajax({
                                url: 'calendar/update_events.php',
                                data: 'title=' + event.title + '&start=' + start + '&end=' + end + '&id=' + event.id,
                                type: "POST",
                            });
                        },
  • Good friend that variable "Event.id" is going correctly ?

  • Change this section in your code success: function (data) { console.log(data); and edit your question by adding the result of console.

  • Yesterday you asked the same question: http://answall.com/questions/61230/howto removeeventos-do-fullcalendar Why not continue with this question? I have even asked you about the existence of this variable event

  • When I enter an event I have to enter the title, and the id is automatically inserted. The variable is set correctly because the use in other methods like "eventDrop" and "eventResize".

  • That’s where the problem is, you are trying to delete from the database an event with the id that "does not exist" or probably does not refer to that event, because it is a Fullcalendar ID and not from your database. Please insert in your question the code where you assemble the calendar and events.

  • John, I marked your question as a duplicate of the one you asked two days ago because your problem is the same. As Kaduamaral has already mentioned, to add more information about your problem, edit the original question. Hug!

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.