我需要通过ajax将开始日期和结束日期发送到服务器,以将它们保存到数据库中。我正在尝试在ajax调用未激发unselect方法之后进行ajax调用。我不知道问题出在哪里。请帮忙。
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
defaultDate: '<?php echo date("Y-m-d") ?>',
defaultView: 'agendaWeek',
selectable: true,
selectHelper: true,
select: function(start, end) {
//var title = prompt('Event Title:');
var title = $("#gym_mbr_name").val();
var eventData;
if (title) {
eventData = { title: title, start: start, end: end };
var calendar_datetime = $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
}
$('#calendar').fullCalendar('unselect');
$.ajax({
url: '<?php echo BASE_URL; ?>ajax/add_membership_schedule.php',
type: 'POST',
data: { start: start, end: end },
beforeSend: function(){ },
complete: function(){ }
}).done(function(resp){
alert(resp);
});
},
editable: true,
eventLimit: true, // allow "more" link when too many events
events: []
});
当我试图提醒resp时,它不会给出任何输出,事实上ajax调用不会自行启动。请帮忙。
这似乎对我有用。
请注意,开始和结束是FCMoments(源自Moments的奇怪生物),在ajax调用中使用它们之前,您需要将它们转换为字符串或其他东西。
此外,尝试使用"success"而不是"done"。
请参阅此处的示例:http://jsfiddle.net/3E8nk/507/
$("#calendar").fullCalendar({
header: {
left: "prev,next today",
center: "title",
right: "month,agendaWeek,agendaDay"
},
defaultDate: "2014-06-12",
editable: true,
selectable: true,
selectHelper: true,
select: function(a, b) {
alert("selected from: " + a.format() + ", to: " + b.format());
$("#calendar").fullCalendar("unselect");
$.ajax({
url: "http://www.google.com",
type: "GET",
data: {
q: "test"
},
dataType: "html",
success: function(a) {
alert("Data: " + a);
},
error: function(a, b) {
alert("Request: " + JSON.stringify(a));
}
});
},
unselect: function() {
alert("unseleted");
},
events: [ {
title: "All Day Event",
start: "2014-06-01"
}, {
title: "Long Event",
start: "2014-06-07",
end: "2014-06-10"
}, {
id: 999,
title: "Repeating Event",
start: "2014-06-09T16:00:00"
}, {
id: 999,
title: "Repeating Event",
start: "2014-06-16T16:00:00"
}, {
title: "Meeting",
start: "2014-06-12T10:30:00",
end: "2014-06-12T12:30:00"
}, {
title: "Lunch",
start: "2014-06-12T12:00:00"
}, {
title: "Birthday Party",
start: "2014-06-13T07:00:00"
}, {
title: "Click for Google",
url: "http://google.com/",
start: "2014-06-28"
} ]
});
如果看这些没有帮助,那么试着发布php生成的内容。
在最新版本的FullCalendar中,我们必须捕获yyyy-mm-dd或相同格式的MOMENT DATE。所以,对我来说,这个代码是有效的:
start = $.fullCalendar.moment(start).format("YYYY-MM-DD HH:mm:ss");
end = $.fullCalendar.moment(end).format("YYYY-MM-DD HH:mm:ss");