TypeError: data is undefined [for ( var i=0, ien=data.length ; i

TypeError: data is undefined [for ( var i=0, ien=data.length ; i

dharmjitdharmjit Posts: 6Questions: 2Answers: 0

Hi All, I am new to datatables and fetching data from ajax call to server side. Below are the code snippet

HTML CODE

User ID First Name Last Name Home Directory Emp Type Active Status Country DN

JS CODE
$(document).ready(function() {

   $('#accountdata').DataTable( {
        processing: true,
        serverSide: true,
        paging:true,
        length:3,
        pagingType: "full_numbers",
        ajax: {"dataType": 'json',
            url : "AccountInformation",
            type : "POST",
            dataSrc:function(json){
                var obj = JSON.parse(json);
                return obj;
            }
   },
              columns: [
                          { data: "login" },
                          { data: "firstName" },
                          { data: "lastName" },
                          { data: "homeDirectory" },
                          { data: "typeCompte" },
                          { data: "etat" },
                          { data: "pays" },
                          { data: "dn" }
   ]
    } );

I am getting response from server in below json
[{"draw":1,"recordsTotal":1000,"recordsFiltered":1000,"data":[{"homeDirectory":"/OrangeMoneyDwh","etat"
:"actif","typeCompte":"libre","pays":"ml","dn":"c = ml,ou=tango,dc=globalreporting,dc=om","login":""
,"firstName":"","lastName":"admin user"}]

upon debugging i get to this line which is causing the issue in datatables.js
var data = _fnAjaxDataSrc( settings, json );

Could anyone help me on this.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • dharmjitdharmjit Posts: 6Questions: 2Answers: 0

    Hi Allan, thanks for your quick response. I am behind the corporate firewall but still able to get the database debugger result. The link is https://debug.datatables.net/enafep
    May be it is of any use

  • allanallan Posts: 63,791Questions: 1Answers: 10,513 Site admin
    Answer ✓

    Just remove your use of ajax.dataSrc. jQuery should automatically decode the JSON. Also, that option doesn't really work with server-side processing.

    Allan

  • dharmjitdharmjit Posts: 6Questions: 2Answers: 0

    Thanks Allan, Able to resolve the issue with your help

This discussion has been closed.