How to send an ajax request to update event in FullCalender UI, when eventDrop is called?

前端 未结 2 1883
梦毁少年i
梦毁少年i 2021-01-06 17:37

I am trying to use this great UI \"FullCalender\" But what I want to do is send an ajax request to update the event data in the database when the user move the event around.

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 17:59

    Take a look at the parameters of the function: delta, minuteDelta and allDay. Those tell you how the event was modified in days, minutes and if it was moved to the allday slot. The event itself should hold an identifier so that you can identify it in your database.

    I made me a helper function updateEventTimes which is simply called from eventDrop and eventResize with an extra boolean parameter.

    The function looks roughly like this:

    /*
     * Sends a request to modify start/end date of an event to the server
     */
    function updateEventTimes(drag, event, dayDelta, minuteDelta, allDay, revertFunc)
    {
      //console.log(event);
      $.ajax({
        url: "update.php",
        type: "POST",
        dataType: "json",
        data: ({
          id: event.id,
          day: dayDelta,
          min: minuteDelta,
          allday: allDay,
          drag: drag
        }),
        success: function(data, textStatus) {
          if (!data)
          {
            revertFunc();
            return;
          }
          calendar.fullCalendar('updateEvent', event);
        },
        error: function() {
          revertFunc();
        }
      });
    };
    

提交回复
热议问题