gpt4 book ai didi

javascript - 在 fullcalendar v4 中编辑和删除事件

转载 作者:行者123 更新时间:2023-11-30 14:04:43 24 4
gpt4 key购买 nike

我想使用 ajax 使用完整日历编辑事件和删除事件,但由于某些原因它不起作用。我认为这是我的代码的一个小问题,我需要一些帮助来修复它。

这适用于使用 fullcalendar v4、mySQL、AJAX、Javascript 的 PHP

   eventDrop: function (info) {
var start = moment(info.event.start).format("Y-MM-DD HH:mm:ss");
var end = moment(info.event.end).format("Y-MM-DD HH:mm:ss");
var title = info.event.title;
$.ajax({
url: 'edit-event.php',
dataType: 'json',
data: { start: start, end: end, title : title },
type: "POST",
success: function (response) {
calendar.fullCalendar( info.event.title);
//Above is the proper way to reference what I am posting with AJAX
displayMessage("Updated Successfully");
}
});
},

eventClick: function (info) {
var deleteMsg = confirm("Do you really want to delete?");
if (deleteMsg) {
$.ajax({
type: "POST",
url: 'delete-event.php',

data: { title : title },
success: function (response) {
if (parseInt(response) > 0) {
calendar.fullCalendar('removeEvents', info.event.title);//call the 'removeEvents' built in function and reference "var title"
displayMessage("Deleted Successfully");
}
}
});
}
},

编辑事件.php

include "dbconnect.php";

if(isset($_POST['title'])){

$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];

$sqlUpdate = "UPDATE events_table SET start='" . $start . "',end='" . $end . "' WHERE title= '$title' ";

$conn->query($sqlUpdate);
}
$conn->close();

删除事件.php

 include "dbconnect.php";

if(isset($_POST['title'])){
$title = $_POST['title'];

echo $sqlDelete = "DELETE from events_table WHERE title='$title'";


mysqli_query($conn, $sqlDelete);
echo mysqli_affected_rows($conn);
}

我希望它在点击时删除事件.然后当它被拖放时,它应该在数据库上更新。

最佳答案

当您使用 fullcalendar V4 时,您不能使用 $.fullCalendar,因为 V4 是纯 javascript(即纯 js/vanilla js),因为评论中提到的 @ADYson V4 不再使用 jQuery。

其次,V4 的 FullCalendar.formatDate(date, settings) 有完全不同的实现,你可以检查所有选项 here .

因此,您可以使用 moments format() 函数,如下所示,

例如

var start = moment(info.event.start).format("Y-MM-DD HH:mm:ss");

这里你在开始时得到了想要的格式,即“Y-MM-DD HH:mm:ss”,确保你有 moment js。

完整代码,

<!DOCTYPE html>
<html>

<head>
<meta charset='utf-8' />
<link href='../packages/core/main.css' rel='stylesheet' />
<link href='../packages/daygrid/main.css' rel='stylesheet' />
<script src='../packages/core/main.js'></script>
<script src='../packages/interaction/main.js'></script>
<script src='../packages/daygrid/main.js'></script>
<script src="https://momentjs.com/downloads/moment.js"></script>
<script>

document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');

var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: ['interaction', 'dayGrid'],
defaultDate: '2019-04-12',
editable: true,
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'All Day Event',
start: '2019-04-01'
},
{
title: 'Long Event',
start: '2019-04-07',
end: '2019-04-10'
},
{
groupId: 999,
title: 'Repeating Event',
start: '2019-04-09T16:00:00'
},
{
groupId: 999,
title: 'Repeating Event',
start: '2019-04-16T16:00:00'
},
{
title: 'Conference',
start: '2019-04-11',
end: '2019-04-13'
},
{
title: 'Meeting',
start: '2019-04-12T10:30:00',
end: '2019-04-12T12:30:00'
},
{
title: 'Lunch',
start: '2019-04-12T12:00:00'
},
{
title: 'Meeting',
start: '2019-04-12T14:30:00'
},
{
title: 'Happy Hour',
start: '2019-04-12T17:30:00'
},
{
title: 'Dinner',
start: '2019-04-12T20:00:00'
},
{
title: 'Birthday Party',
start: '2019-04-13T07:00:00'
},
{
title: 'Click for Google',
url: 'http://google.com/',
start: '2019-04-28'
}
],
eventDrop: function (info) {
var start = moment(info.event.start).format("Y-MM-DD HH:mm:ss");
var end = moment(info.event.start).format("Y-MM-DD HH:mm:ss");
$.ajax({
url: 'edit-event.php',
data: { start: start, end: end, id: id },
type: "POST",
success: function (response) {
displayMessage("Updated Successfully");
}
});
},

eventClick: function (info) {
var deleteMsg = confirm("Do you really want to delete?");
if (deleteMsg) {
$.ajax({
type: "POST",
url: 'delete-event.php',
data: { id: id },
success: function (response) {
if (parseInt(response) > 0) {
info.event.remove();
displayMessage("Deleted Successfully");
}
}
});
}
}
});

calendar.render();
});

</script>
<style>
body {
margin: 40px 10px;
padding: 0;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
}

#calendar {
max-width: 900px;
margin: 0 auto;
}
</style>
</head>

<body>

<div id='calendar'></div>

</body>

</html>

关于javascript - 在 fullcalendar v4 中编辑和删除事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55666779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com