By pressing the "btn_insert" button, once the data is saved, I need the events to be updated, and for that I am using .fullCalendar ('refetchEvents') that should reload the events, but it does not and I do not know why. I leave the code.
This is the fullcalendar code, which brings the events of the Database
$.post('<?php echo base_url();?>cCalendar/geteventos',
function(data){
//alert(data);
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
defaultDate: new Date(),
navLinks: true, // can click day/week names to navigate views
businessHours: true, // display business hours
editable: true,
events: $.parseJSON(data),
dayClick: function(date, jsEvent, view) {
date_last_clicked = $(this);
$(this).css('background-color', '#bed7f3');
$('#modal_registrar').modal();
},
minTime: "08:30:00",
maxTime: "23:00:00"
});
});
The function to save the data
$("#btn_insert").click(function(){
var rut_usu = $("#rut_usu").val();
var rut_estu = $("#rut_estu").val();
var id_mot = $("#id_mot").val();
var fecha_ini = $("#fecha_ini").val();
var fecha_ter = $("#fecha_ter").val();
$.ajax({
url: "<?php echo base_url(); ?>" + "cCalendar/insertar_cita/",
type: 'post',
data: { "rut_usu": rut_usu, "rut_estu": rut_estu, "id_mot" : id_mot , "fecha_ini": fecha_ini , "fecha_ter": fecha_ter},
success: function(response){
$("#modal_registrar").modal('hide');
document.getElementById("form_ingresar").reset();
$("#modal_confirmar").modal('show');
$('#calendar').fullCalendar("refetchEvents");
//console.log(response);
}
});