FullCalendar does not update automatically when adding an event

0

Please read the comment in each code.

The code of the file that inserts the data is:

<?php
header('Content-Type: application/json');
$conexion = new PDO ("mysql:host=localhost;dbname=scouts_601_palmira","root","");
if(isset($_GET['id'])){
$id = $_GET['id'];
}
$accion = (isset($_GET['accion']))?$_GET['accion']:'leer';
switch ($accion) {
case 'agregar':
    $sql = "INSERT INTO Eventos(title, start, end, Tipo, Lugar, Fecha_encuentro, Hora_encuentro, Punto_encuentro, Costo, Costo_incluye, Material_individual, Material_equipos, Ficha, color, textColor, Id_rama) VALUES(:title, :start, :end, :Tipo, :Lugar, :Fecha_encuentro, :Hora_encuentro, :Punto_encuentro, :Costo, :Costo_incluye, :Material_individual, :Material_equipos, :Ficha, :color, :textColor, :Id_rama)";
    $sentencia = $conexion -> prepare($sql);
    $respuesta = $sentencia -> execute(array(
        "title" => $_POST['title'],
        "start" => $_POST['start'],
        "end" => $_POST['end'],
        "Tipo" => $_POST['Tipo'],
        "Lugar" => $_POST['Lugar'],
        "Fecha_encuentro" => $_POST['Fecha_encuentro'],
        "Hora_encuentro" => $_POST['Hora_encuentro'],
        "Punto_encuentro" => $_POST['Punto_encuentro'],
        "Costo" => $_POST['Costo'],
        "Costo_incluye" => $_POST['Costo_incluye'],
        "Material_individual" => $_POST['Material_individual'],
        "Material_equipos" => $_POST['Material_equipos'],
        "Ficha" => $_POST['Ficha'],
        "color" => $_POST['color'],
        "textColor" => $_POST['textColor'],
        "Id_rama" => $_POST['Id_rama']
    ));
    echo json_encode($respuesta);
    //ESTE ECHO PARECE QUE NO DEVUELVE TRUE, AUN CUANDO SI SE INSERTAN LOS DATOS EN LA BD
    break;
case 'modificar':
    # code...
    echo "Instruccion modificar";
    break;
case 'eliminar':
    # code...
    echo "Instruccion eliminar";
    break;
default:
    $sql = "SELECT * FROM Eventos".(isset($id) ? " WHERE Id_rama = :Id_rama" : "");
    $sentencia = $conexion -> prepare($sql);
    if(isset($id)){
        $sentencia -> bindParam(':Id_rama', $id, PDO::PARAM_STR);
    }
    $sentencia -> execute();
    $resultado = $sentencia -> fetchAll(PDO::FETCH_ASSOC);
    echo json_encode($resultado);
    break;
}
?>

And the code to capture the echo that should return true is:

<script type="text/javascript">
$("#btn-agregar").click(function() {
    recolectarDatosGUI();
    registrarInformacion('agregar', NuevoEvento);
});
$("#btn-borrar").click(function() {
    recolectarDatosGUI();
    registrarInformacion('eliminar', NuevoEvento);
});
$("#btn-actualizar").click(function() {
    recolectarDatosGUI();
    registrarInformacion('modificar', NuevoEvento);
});

function recolectarDatosGUI() {
    NuevoEvento = {
        Id:$('#id').val(),
        title:$('#nombre').val(),
        start:$('#fecha-inicio').val()+" "+$('#hora-inicio').val(),
        end:$('#fecha-cierre').val()+" "+$('#hora-cierre').val(),
        Tipo:$('#tipo').val(),
        Lugar:$('#lugar').val(),
        Fecha_encuentro:$('#fecha-encuentro').val(),
        Hora_encuentro:$('#hora-encuentro').val(),
        Punto_encuentro:$('#punto-encuentro').val(),
        Costo:$('#costo').val(),
        Costo_incluye:$('#costo-incluye').val(),
        Material_individual:$('#material-individual').val(),
        Material_equipos:$('#material-equipos').val(),
        Ficha:"Ficha generica",//$('#ficha').val(),
        color:$('#color').val(),
        textColor:$('#color-texto').val(),
        Id_rama:$('#id-rama').val(),
    };
}
function registrarInformacion(accion,objEvento,modal) {
    $.ajax({
        type:'POST',
        url:'../Sql/ArregloEventos.php?accion='+accion,
        data:objEvento,
        success:function(msg){
            if(msg){
                $('#Calendario_Web').fullCalendar('refetchEvents');
                if(!modal) {
                    $("#modal").modal('toggle');
                }
            }
        },
        error:function(){
            alert("Hay un error...");
        }
    });
}
</script>

I appreciate any help for this problem in advance.

    
asked by Danyel Melendez Ramirez 24.10.2018 в 17:41
source

0 answers