我正在为一个项目使用全日历。我无法将新事件插入 mysql 数据库。
它可以使用 AJAX 完成,但我无法将变量从 JS 传递到 php 代码。
这是我的代码:
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
} ,
defaultView: 'month',
weekends: true,
selectable: true,
selectHelper: false,
allDayText: 'ore di lavoro',
editable: true,
theme: true,
select: function(start, end, allDay,jsEvent,view) {
if (view.name === "month") {
$('#calendar').fullCalendar('gotoDate', start);
$('#calendar').fullCalendar('changeView', 'agendaDay');
} else {
var title = prompt('Riparazione racchetta da tennis:');
if (title) {
calendar.fullCalendar('renderEvent',
{
title: title,
start: start,
end: end,
allDay: allDay
},
true // make the event "stick"
);
$.ajax({
type: "POST",
url: "kot.php",
data: "title=" + title + "&start=" + start + "&end=" + end,
});
$('#calendar').fullCalendar('refetchEvents');
}
calendar.fullCalendar('unselect');
}
},
eventSources: [
// your event source
{
url: 'json-events.php',
type: 'POST',
error: function() {
alert('there was an error while fetching events!');
},
//color: 'blue', // a non-ajax option
//textColor: 'black' // a non-ajax option
},
// any other sources...
{
url: 'kot.php',
type: 'POST',
data: {
custom_param1: 'something',
custom_param2: 'somethingelse',
custom_param3: 'somethingelsee'
},
error: function() {
alert('there was an error while fetching events!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
}
]
});
});