Capture $.getJson value is coming Undefined

Asked

Viewed 82 times

1

I’m trying to assemble a table from a JSON that I receive from a page php, meanwhile when I do the append the captured value appears as Undefined.

$.getJSON("getEventoCategoria.php", {ID_EVT_Evento: ID},function (data) {
                var tabledata = "";
                console.log(data);
                console.log(data[0].DSC_Nome);
                $.each(data, function (index, item) {
                    console.log(item.DSC_Nome);
                    console.log(item.VLR_Inscricao);
                    
                    $('#conteudoTabelaCategoria')
                            .append(
                                    "<tr>" +
                                    "<td>" + item.DSC_Nome + "</td>" +
                                    "<td>" + item.VLR_Inscricao + "</td>" +
                                    "<td>" + item.DT_Inicio_Valor + "</td>" +
                                    "<td>" + item.DT_Fim_Valor + "</td>" +
                                    "</tr>"
                                    );
                });
            });

in php file:

<?php

$ID_EVT_Evento = $_REQUEST['ID_EVT_Evento'];
require_once './actions/aEvt_Evento_Categoria.php';

$EventoCategoria = new aEvt_Evento_Categoria();

$arr[] = $EventoCategoria->selectCategoriasDoEvento($ID_EVT_Evento);

echo json_encode($arr);

when I do a direct get by the url it displays me the following JSON:

[[{"ID_Evento_Categoria":"528c234df006558ae470fa0ccabe7892","DSC_Nome":"Categoria 01","VLR_Inscricao":"100.00","DT_Inicio_Valor":"2015-01-01","DT_Fim_Valor":"2015-12-31","ID_EVT_Evento":"528c234df006558ae470fa0ccabe7892"}]]

I’ve put some debug logs in. Someone’s been through this trouble?

  • What returns the console.log(data) ?

  • 0: Array[1] 0: Object Dsc_name: "Category 01" Dt_fim_value: "2015-12-31" Dt_start_value: "2015-01-01" Id_evt_event: "528c234df006558ae470fa0ccabe7892" Id_evento_category: "528c234df006558ae470fa0ccabe7892" Vlr_registration: "100.00"

  • in php appears like this:

  • [[{"ID_Evento_Categoria":"528c234df006558ae470fa0ccabe7892","DSC_Nome":"Categoria 01","VLR_Inscricao":"100.00","DT_Inicio_Valor":"2015-01-01","DT_Fim_Valor":"2015-12-31","ID_EVT_Evento":"528c234df006558ae470fa0ccabe7892"}]]

  • Stick to the question what your file getEventoCategoria.php ago !!!

  • put into question.

  • in that line $arr[] = $Eventocategoria->selectCategoriesDoEvento($Id_evt_event); put some $arr = $Eventocategoria->selectCategoriesDoEvento($Id_evt_event); because you are creating array of array in my view! that will work !!!

  • HALLELUJAH............

  • Was that right....

  • 1

    Thank you very much.

  • I think you’d better rule that out!

Show 6 more comments

1 answer

2

Solved. I only removed the "[]" in the "arr" variable in the php file.

Browser other questions tagged

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