javascript-jQuery FullCalendar如何在ajax调用后显示数据而不刷新页面
作者:互联网
我正在尝试将jQuery FullCalendar与PHP和MySQL集成.我的问题是,当我通过选择带有AJAX的天来插入新事件时,我不知道如何在不刷新页面的情况下显示此新添加的事件..所以基本上这是FullCalendar调用:
var calendar = $('#calendar').fullCalendar({
editable: true,
firstDay: 1,
header: {
left: 'month, agendaWeek, agendaDay',
center: 'title',
right: 'prev, next, today'
},
// receive events from DB
events: {
url: 'events.php',
type: 'POST',
cache: false,
error: function() {
alert('ERROR');
}
},
buttonIcons: {
prev: 'left-single-arrow',
next: 'right-single-arrow'
},
// Convert the allDay from string to boolean
eventRender: function(event, element, view) {
if (event.allDay === 'true') {
event.allDay = true;
} else {
event.allDay = false;
}
element.find('.fc-event-title').append("<br/>" + event.description);
},
selectable: true,
selectHelper: true,
select: function(start, end, allDay) {
var start = moment(start).format("YYYY-MM-DD HH:mm:ss");
var end = moment(end).format("YYYY-MM-DD HH:mm:ss");
var user_id = <?php echo $_SESSION['user_id']; ?>
// to unix
start = moment(start).unix();
end = moment(end).unix();
$('#myModal').modal({
remote: 'modals/add_event.php?start='+start+'&end='+end+'&id='+user_id
});
}
});
我要进行事件插入的地方是:
select: function(start, end, allDay) {
var start = moment(start).format("YYYY-MM-DD HH:mm:ss");
var end = moment(end).format("YYYY-MM-DD HH:mm:ss");
var user_id = <?php echo $_SESSION['user_id']; ?>
// to unix
start = moment(start).unix();
end = moment(end).unix();
$('#myModal').modal({
remote: 'modals/add_event.php?start='+start+'&end='+end+'&id='+user_id
});
}
这将打开模式对话框,我将在其中提交日历数据,然后再通过AJAX向DB提交数据.此后,我不知道如何在不刷新页面的情况下显示新添加的数据.
另外:这是我提交模态对话框形式时的AJAX调用:
$.ajax({
type : "POST",
url : "ajax/add_event.php?start="+start.unix()+'&end='+end.unix()+'&id='+user_id,
data : $("#smart-form-event").serialize(),
success : function(data, status, xhr) {
$.smallBox({
title : "Event added successfully",
content : "<i class='fa fa-exclamation'></i> <i></i>",
color : "#659265",
iconSmall : "fa fa-check fa-2x fadeInRight animated",
timeout : 4000
});
$("#myModal").modal('hide');
}
});
谢谢!
解决方法:
您可以在插入新事件后调用“ refetchEvents”
http://fullcalendar.io/docs/event_data/refetchEvents/
$(‘#calendar’).fullCalendar(‘refetchEvents’);
...
success : function(data, status, xhr) {
$.smallBox({
title : "Event added successfully",
content : "<i class='fa fa-exclamation'></i> <i></i>",
color : "#659265",
iconSmall : "fa fa-check fa-2x fadeInRight animated",
timeout : 4000
});
$("#myModal").modal('hide');
$('#calendar').fullCalendar('refetchEvents');
}
...
标签:ajax,fullcalendar,javascript,php,jquery 来源: https://codeday.me/bug/20191028/1955512.html