Alejandro Muñoz Alejandro Muñoz - 5 months ago 6
Javascript Question

Post JSON Jquery show

I'm still trying to get a JSON response, deplegue in a div ... I pass to mostar and tell them


script


$('select#mes').on('change',function(){

var valor = $(this).val();
var route = "http://localhost/UJOBB/public/ADIC/ListaM";
var token = document.getElementById('token').getAttribute('content')


if(valor != null){

$.ajax({
url: route,
headers: {'X-CSRF-TOKEN': token},
type: 'POST',
dataType: 'json',
data:{mes: valor},
beforeSend: function () {
$("#resultado").html("Procesando, espere por favor...");
},
success: function(users){
$("#resultado").html(JSON.stringify(users));
},
error: function() {

}
});
}
else{
}


});


the post worked ok and I json response but fails to deploy in row


JSON response


{"users":[{"id":1,"Fecha":"Vier 06 Mayo","EquipoA":"Edu","EquipoB":"Juan XXIII","Categoria":"sub18","Cancha":"EDU","Hora":"2016-06-14 16:00:00","Numero_J1":"94","Nombre_J1":"Sebastián","Apellido_J1":"Vilizio","Check_J1":1,"Numero_J2":"127","Nombre_J2":"Santiago","Apellido_J2":"Gomez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:37","updated_at":"2016-06-14 18:57:37"},{"id":2,"Fecha":"Sáb 07 Mayo","EquipoA":"Safa","EquipoB":"ISASA","Categoria":"sub18","Cancha":"Safa","Hora":"2016-06-14 16:15:00","Numero_J1":"45","Nombre_J1":"M.","Apellido_J1":"Fantauzzi","Check_J1":1,"Numero_J2":"141","Nombre_J2":"Diego","Apellido_J2":"Gomez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:37","updated_at":"2016-06-14 18:57:37"},{"id":3,"Fecha":"Sáb 07 Mayo","EquipoA":"Safa","EquipoB":"ISASA","Categoria":"sub16","Cancha":"Safa","Hora":"2016-06-14 17:45:00","Numero_J1":"45","Nombre_J1":"Marcelo","Apellido_J1":"Fantauzzi","Check_J1":1,"Numero_J2":"141","Nombre_J2":"Diego","Apellido_J2":"Gomez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":4,"Fecha":"Sáb 07 Mayo","EquipoA":"Safa","EquipoB":"ISASA","Categoria":"sub14","Cancha":"Safa","Hora":"2016-06-14 19:15:00","Numero_J1":"45","Nombre_J1":"Marcelo","Apellido_J1":"Fantauzzi","Check_J1":1,"Numero_J2":"141","Nombre_J2":"Diego","Apellido_J2":"Gomez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":5,"Fecha":"Sáb 07 Mayo","EquipoA":"Seminario","EquipoB":"Elbio","Categoria":"sub18","Cancha":"Seminario","Hora":"2016-06-14 15:30:00","Numero_J1":"52","Nombre_J1":"M.","Apellido_J1":"Rial","Check_J1":1,"Numero_J2":"120","Nombre_J2":"Jose","Apellido_J2":"Perez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":6,"Fecha":"Sáb 07 Mayo","EquipoA":"Seminario","EquipoB":"Elbio","Categoria":"sub14","Cancha":"Seminario","Hora":"2016-06-14 17:00:00","Numero_J1":"52","Nombre_J1":"M.","Apellido_J1":"Rial","Check_J1":1,"Numero_J2":"120","Nombre_J2":"Jose","Apellido_J2":"Perez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":7,"Fecha":"Sáb 07 Mayo","EquipoA":"Seminario","EquipoB":"Elbio","Categoria":"sub16","Cancha":"Seminario","Hora":"2016-06-14 18:30:00","Numero_J1":null,"Nombre_J1":null,"Apellido_J1":null,"Check_J1":1,"Numero_J2":"120","Nombre_J2":"Jose","Apellido_J2":"Perez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":8,"Fecha":"Sáb 07 Mayo","EquipoA":"La Mennais","EquipoB":"Frances","Categoria":"sub14","Cancha":"La Mennais","Hora":"2016-06-14 16:30:00","Numero_J1":"48","Nombre_J1":"A.","Apellido_J1":"Labiuza","Check_J1":1,"Numero_J2":"134","Nombre_J2":"G.","Apellido_J2":"Brum","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":9,"Fecha":"Sáb 07 Mayo","EquipoA":"La Mennais","EquipoB":"Frances","Categoria":"sub16","Cancha":"La Mennais","Hora":"2016-06-14 18:00:00","Numero_J1":"48","Nombre_J1":"A.","Apellido_J1":"Labiuza","Check_J1":1,"Numero_J2":"134","Nombre_J2":"G.","Apellido_J2":"Brum","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":10,"Fecha":"Sáb 07 Mayo","EquipoA":"UAS","EquipoB":"Preu","Categoria":"sub18","Cancha":"UAS","Hora":"2016-06-14 15:00:00","Numero_J1":"39","Nombre_J1":"Alvaro","Apellido_J1":"Aunchayna","Check_J1":1,"Numero_J2":"139","Nombre_J2":"G.","Apellido_J2":"Cancela","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":11,"Fecha":"Sáb 07 Mayo","EquipoA":"Impulso","EquipoB":"San Jose Prov","Categoria":"sub16","Cancha":"UAS","Hora":"2016-06-14 16:30:00","Numero_J1":"39","Nombre_J1":"Alvaro","Apellido_J1":"Aunchayna","Check_J1":1,"Numero_J2":"139","Nombre_J2":"G.","Apellido_J2":"Cancela","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":12,"Fecha":"Vier 13 Mayo","EquipoA":"L. Militar","EquipoB":"Isasa","Categoria":"sub18","Cancha":"L. Militar","Hora":"2016-06-14 15:30:00","Numero_J1":"39","Nombre_J1":"Alvaro","Apellido_J1":"Aunchayna","Check_J1":1,"Numero_J2":"39","Nombre_J2":"Alvaro ","Apellido_J2":"Aunchayna ","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":13,"Fecha":"Sáb 14 Mayo","EquipoA":"San Juan ","EquipoB":"Frances","Categoria":"sub14","Cancha":"San Juan ","Hora":"2016-06-14 17:00:00","Numero_J1":"54","Nombre_J1":"D.","Apellido_J1":"Spilman","Check_J1":1,"Numero_J2":"23","Nombre_J2":"G","Apellido_J2":"Cardozo","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":14,"Fecha":"Sáb 14 Mayo","EquipoA":"San Juan ","EquipoB":"Frances","Categoria":"sub16","Cancha":"San Juan ","Hora":"2016-06-14 18:30:00","Numero_J1":"54","Nombre_J1":"D.","Apellido_J1":"Spilman","Check_J1":1,"Numero_J2":"23","Nombre_J2":"G","Apellido_J2":"Cardozo","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":15,"Fecha":"Sáb 21 Mayo","EquipoA":"UAS","EquipoB":"Elbio","Categoria":"sub18","Cancha":"UAS","Hora":"2016-06-14 12:30:00","Numero_J1":"141","Nombre_J1":"Diego","Apellido_J1":"Gomez","Check_J1":1,"Numero_J2":"131","Nombre_J2":"D.","Apellido_J2":"Lopez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":16,"Fecha":"Sáb 21 Mayo","EquipoA":"Crandon","EquipoB":"Sta. Elena","Categoria":"sub14","Cancha":"Crandon","Hora":"2016-06-14 16:45:00","Numero_J1":"64","Nombre_J1":"W.","Apellido_J1":"Chamorro","Check_J1":1,"Numero_J2":"133","Nombre_J2":"P.","Apellido_J2":"Borges","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":17,"Fecha":"Sáb 21 Mayo","EquipoA":"Crandon","EquipoB":"Sta. Elena","Categoria":"sub16","Cancha":"Crandon","Hora":"2016-06-14 18:15:00","Numero_J1":"64","Nombre_J1":"W.","Apellido_J1":"Chamorro","Check_J1":1,"Numero_J2":"133","Nombre_J2":"P.","Apellido_J2":"Borges","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":18,"Fecha":"Sáb 21 Mayo","EquipoA":"Seminario","EquipoB":"San Juan II","Categoria":"sub14","Cancha":"San Juan ","Hora":"2016-06-14 15:30:00","Numero_J1":"86","Nombre_J1":"M.","Apellido_J1":"Correa","Check_J1":1,"Numero_J2":"126","Nombre_J2":"D.","Apellido_J2":"Orrico","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":19,"Fecha":"Sáb 21 Mayo","EquipoA":"La Mennais","EquipoB":"San Juan ","Categoria":"sub16","Cancha":"San Juan ","Hora":"2016-06-14 17:00:00","Numero_J1":"86","Nombre_J1":"M.","Apellido_J1":"Correa","Check_J1":1,"Numero_J2":"126","Nombre_J2":"D.","Apellido_J2":"Orrico","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":20,"Fecha":"Sáb 21 Mayo","EquipoA":"La Mennais","EquipoB":"San Juan ","Categoria":"sub18","Cancha":"San Juan ","Hora":"2016-06-14 18:30:00","Numero_J1":"86","Nombre_J1":"M.","Apellido_J1":"Correa","Check_J1":1,"Numero_J2":"126","Nombre_J2":"D.","Apellido_J2":"Orrico","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":21,"Fecha":"Sáb 21 Mayo","EquipoA":"Safa","EquipoB":"Juan XXIII","Categoria":"sub18","Cancha":"Safa","Hora":"2016-06-14 16:15:00","Numero_J1":"119","Nombre_J1":"Sandra","Apellido_J1":"Lopez","Check_J1":1,"Numero_J2":"138","Nombre_J2":"N","Apellido_J2":"Daguerre","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":22,"Fecha":"Sáb 21 Mayo","EquipoA":"Seminario","EquipoB":"Isasa","Categoria":"sub18","Cancha":"Seminario","Hora":"2016-06-14 17:00:00","Numero_J1":"47","Nombre_J1":"M.","Apellido_J1":"Galli","Check_J1":1,"Numero_J2":"127","Nombre_J2":"Santiago","Apellido_J2":"Gomez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":23,"Fecha":"Sáb 21 Mayo","EquipoA":"Seminario","EquipoB":"Isasa","Categoria":"sub16","Cancha":"Seminario","Hora":"2016-06-14 18:30:00","Numero_J1":"47","Nombre_J1":"M.","Apellido_J1":"Galli","Check_J1":1,"Numero_J2":"127","Nombre_J2":"Santiago","Apellido_J2":"Gomez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":24,"Fecha":"Sáb 28 Mayo","EquipoA":"Safa","EquipoB":"Impulso ","Categoria":"sub16","Cancha":"Safa","Hora":"2016-06-14 16:15:00","Numero_J1":"110","Nombre_J1":"G.","Apellido_J1":"Gonzalez","Check_J1":1,"Numero_J2":"120","Nombre_J2":"J.","Apellido_J2":"Perez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":25,"Fecha":"Sáb 28 Mayo","EquipoA":"Safa","EquipoB":"Preu","Categoria":"sub18","Cancha":"Safa","Hora":"2016-06-14 17:45:00","Numero_J1":"110","Nombre_J1":"G.","Apellido_J1":"Gonzalez","Check_J1":1,"Numero_J2":"120","Nombre_J2":"J.","Apellido_J2":"Perez","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"},{"id":26,"Fecha":"Sáb 28 Mayo","EquipoA":"San Juan ","EquipoB":"L. Militar","Categoria":"sub18","Cancha":"San Juan ","Hora":"2016-06-14 14:30:00","Numero_J1":"122","Nombre_J1":"M.","Apellido_J1":"Coghlan","Check_J1":1,"Numero_J2":"133","Nombre_J2":"P.","Apellido_J2":"Borges","Check_J2":1,"Mes":"May","created_at":"2016-06-14 18:57:38","updated_at":"2016-06-14 18:57:38"}]}



html


<table class="table table-striped table-hover">
<thead>
<th>Fecha</th>
<th>Cancha</th>
<th>Partido</th>
<th>Juez - 1</th>
<th>Juez - 2</th>
<th>Estado</th>
</thead>
<tbody>
<span id="resultado">0</span>
</tbody>
</table>

Answer

In success handler you have JSON object which you can use to populate the table.

...
success: function(data){
   var tbody = $('.table.table-striped > tbody');
   $(data.users).each(function(index, user){
     $('<tr />')
       .append($('<td />').html(user.Fecha))
       .append($('<td />').html(user.Categoria))
       .appendTo(tbody);
   });//each
}//success
...