我遇到了fullcalendar dayClick功能的问题。
var ctx = document.getElementById("myChart").getContext("2d");
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
data: [65, 0, 80, 81, 56, 85, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.2)",
data: [0, 0, 0, 0, 0, 0, 0]
}
]
};
var data2 = [28, 48, 40, 19, 86, 27, 90];
var done = false;
var myLineChart = new Chart(ctx).Line(data, {
animationEasing: 'linear',
onAnimationComplete: function () {
if (!done) {
myLineChart.datasets[1].points.forEach(function (point, i) {
point.value = data2[i];
});
myLineChart.update();
done = true;
}
}
});
这是我现在的职能。
问题是我第一次点击日期单元并发送ajax请求一切都很好,但是如果我没有刷新页面而我点击另一天,单元格dayClick: function(date) {
$('#start_date').val(date.format('YYYY-MM-DD H:mm'));
$('#new-appointment-modal').modal();
$('#new-appointment-form').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '/api/appointments',
data: $('#new-appointment-form').serializeJSON(),
headers: {
'Accept': 'application/json',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
}).done(function (response) {
$('#calendar').fullCalendar('refetchEvents');
$.each(response, function(index, value) {
toastr[index](value);
});
$('#new-appointment-modal').modal('hide');
}).fail(function(response) {
$.each(response.responseJSON, function(index, value) {
toastr[index](value);
});
});
});
}
将发送两个ajax请求,如果在那之后我点击另一天,它将发送三个ajax请求,依此类推。
我不明白这是什么问题。