我需要使用ajax url传递上个月和下个月的值以按月获取事件数据,我已尝试过但未获得相关输出,此处通过单击上一个和下一个按钮从此获取月份值div $('div.fc-center')。text()并通过month_year输入id获取这些值,在将month_year值传递给load_events页面的事件中,以获取所选月份的数据。
$(".fc-next-button").click(function()
{
alert("next");
var temp1 = $('div.fc-center').text();
alert(temp1);
$('#month_year').val(temp1);
});
$('#calendar1').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
},
defaultDate: '<?php echo date('Y-m-d'); ?>',
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
showNonCurrentDates: false,
events: function( start, end, timezone, callback ) {
$.ajax({
url: 'load_events.php',
dataType: 'json',
data: {
start: start.unix(),
end: end.unix(),
month_year: $('#month_year').val(),
var cu_date = new Date($('#calendar1').fullCalendar('getDate')),
var month_integer = date.getMonth(),
var year_integer = date.getFullYear(),
},
success: function(doc) {
console.log(doc);
var events = [];
$(doc).find('event').each(function() {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start')
});
$("#calendar1").fullCalendar("rerenderEvents");
});
callback(doc);
}
});
},
});
PHP:
<?php
include('../config.php');
$start = $_GET['start'];
$start_dd = date('Y-m-d',$start);
$end = $_GET['end'];
$end_dd = date('Y-m-d',$end);
$data = array();
$data[] = array(
'id' => 1, 'title' => date('Y-m-d').'-'.$start_dd.'-'.$end_dd,
'start' => date('Y-m-d'),
'end' => date('Y-m-d'),
);
echo json_encode($data);
?>
输出:在当月显示输出
start.unix() - &gt; 29.04.2018和end.unix - &gt; 2018年6月10日