TypeError: data is undefined

TypeError: data is undefined

mldgatomldgato Posts: 13Questions: 3Answers: 0

Hi, I have this error: TypeError: data is undefined
this is my javascript code:

$(document).ready(function()
{
    var tabla = $('#LosUsuarios').dataTable(
    {
        "processing": true,
            "serverSide": true,
        "ajax":
        {
            "url": "listadoUsuarios.php",
            "type": "POST"
        },
        "columns": [
            { "Usuarios": "Nombres" },
            { "Usuarios": "Apellidos" },
            { "Usuarios": "Usuario" },
            { "Usuarios": "Email" },
            { "Usuarios": "Rol" }
        ]
    });
 });

My json result is:

{"Usuarios":[{"Nombres":"Manuel Lisandro","Apellidos":"Dardón López","Usuario":"mldgato","Email":"manueldardon@hotmail.com","Rol":"1"},{"Nombres":"Luisa María","Apellidos":"Pérez Rodríguez","Usuario":"lperez","Email":"lperez@manueldardon.net","Rol":"2"},{"Nombres":"Walter Antonio","Apellidos":"Ceballos Carranza","Usuario":"wceballos","Email":"wceballos@manueldardon.net","Rol":"3"},{"Nombres":"Cesar Sebastían","Apellidos":"Domínguez Contreras","Usuario":"cdominguez","Email":"cdominguez@gmail.com","Rol":"3"},{"Nombres":"Maria Silvia","Apellidos":"Estrada Morales","Usuario":"mestrada","Email":"mestrada@gmail.com","Rol":"3"}]}

you can see in:

sigeco.manueldardon.net/usuarios/listadoUsuarios.php

I followed the following example:
https://datatables.net/examples/server_side/post.html

But it does not work, someone can guide me please

This question has an accepted answers - jump to answer

Answers

  • fedegirofedegiro Posts: 10Questions: 5Answers: 0
    edited November 2016

    the Json is valid.
    where is the page with the JS code and the html table?

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin
    Answer ✓

    { "Usuarios": "Nombres" },

    There is no Usuarios property in DataTables. I think you mean:

     { "data": "Nombres" },
    

    Also use the ajax.dataSrc option set to be Usuarios to tell DataTables that is where the data array in your JSON is.

    Allan

  • mldgatomldgato Posts: 13Questions: 3Answers: 0

    Thanks Allan, it worked by changing the name of the array with data, but the searcher and pagination does not work

  • mldgatomldgato Posts: 13Questions: 3Answers: 0

    Well the searcher and pagination works, I removed the part of processing with the server, thank you very much.

This discussion has been closed.