Doubt when returning string json to Fullcalendar event

Asked

Viewed 312 times

2

I have a question. I’m using Fullcalendar on a project. I can display the data registered in the database normally.

My problem is in the eventClick: did so:

var date = new Date();
    var d = date.getDate(),
            m = date.getMonth(),
            y = date.getFullYear();
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        buttonText: {
            today: 'today',
            month: 'month',
            week: 'week',
            day: 'day'
        },
        eventClick: function (event, jsEvent, view) {
            $.ajax({
                type: "POST",
                dataType: "json",
                url: '<?php echo base_url(); ?>' + 'agenda/get_dados_evento/',
                data: event.id,
                async: true,
                success: function (response) {
                    $("#evento").html(response.id_carro);
                    $("#modal").modal();
                }
            });
        },
        //Random default events
        events: <?php print_r($eventos); ?>,
        editable: true,
        droppable: true, // this allows things to be dropped onto the calendar !!!
    });

When I click on an event registered in the calendar, Event.id is sent to the controller

function get_dados_evento() {

    $id_agenda = $this->input->post('id');
    //$id_agenda = '24';

    $query = $this->model_agenda->get_dados_evento($id_agenda);

    echo json_encode($query->result());
}

here is the model:

function get_dados_evento($id_agenda){

    $this->db->select(""
            . "agenda.id as id_agenda,"
            . "agenda.id_carro as id_carro_agenda,"
            . "agenda.title as titulo_agenda,"
            . "agenda.start as dt_inicial,"
            . "agenda.end as dt_final,"
            . "agenda.dt_cadastro as data_cadastro_agenda,"
            . "carro.id as id_carro,"
            . "carro.modelo as modelo_carro,"
            . "carro.placa as placa_carro,"
            . "carro.fabricante as fabricante_carro,"
            . "carro.tipo as tipo_carro,"
            . "carro.ano_fabricacao as ano_fabricacao_carro,"
            . "carro.kilometragem as kilometragem_inicial_carro,"
            . "carro.status as status_carro,"
            . "carro.dt_cadastro as data_cadastro_carro");
    $this->db->where('agenda.id', $id_agenda);
    $this->db->join('carro', 'agenda.id_carro = carro.id', 'inner');
    $query = $this->db->get('agenda');

    return $query;
}

My problem is time to display the information in the view... if I put the following code in the block success:function(response){ console.debug(response); } it prints the object. And the time I try to display console.debug(response.id_carro); it gives as undefined

  • But because when passing to view does not pass in array? then only displays the value that is in the array()?

  • Andre and how would you do it?

  • 1

    I was able to solve it. In the agenda model, I have a method that runs in the class call, it returns all registered events. What I did was change this method to bring all the information from the tables related to the event (car data, customer data and event data). So I already have the information in the Calendar object.

1 answer

1

As already solved the problem maybe you can decrease the code of:

eventClick: function (event, jsEvent, view) {
    $.ajax({
            type: "POST",
            dataType: "json",
            url: '<?php echo base_url(); ?>' + 'agenda/get_dados_evento/',
            data: event.id,
            async: true,
            success: function (response) {
                $("#evento").html(response.id_carro);
                $("#modal").modal();
            }
    });
}

To

$.post('<?php echo base_url(); ?>' + 'agenda/get_dados_evento/', event.id, function(response){
    $("#evento").html(response.id_carro);
    $("#modal").modal();
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.