Uncaught TypeError: Cannot read properties of undefined (reading 'length')

Uncaught TypeError: Cannot read properties of undefined (reading 'length')

ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

I am new to this forum and I want to request help with a problem that I have, messages that appear in the console and datatable does not show the data in the table, I will describe: the problem.

Uncaught TypeError: Cannot read properties of undefined (reading 'length')
at jquery.dataTables.min.js:4:32902
at Object.e [as success] (jquery.dataTables.min.js:4:25769)
at c (jquery-3.6.4.min.js:2:28447)
at Object.fireWith [as resolveWith] (jquery-3.6.4.min.js:2:29192)
at l (jquery-3.6.4.min.js:2:80176)
at XMLHttpRequest.<anonymous> (jquery-3.6.4.min.js:2:82630)

this is my js code

let tblAdmins;
document.addEventListener("DOMContentLoaded", function(){
tblAdmins = $('#tblAdmins').DataTable({
ajax: {
url: base_url + "/Admin/listar",
dataScr: ""
},
columns: [
{"data" : "id"},
{"data" : "usuario"},
{"data" : "nombre"},
{"data" : "clave"},
{"data" : "estado"},
]
});
})

this is my table

Id Usuario Nombre Clave Estado

Replies

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    What is the response from the server for the base_url + "/Admin/listar", file?

    Allan

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Maybe its a copying error, but you have dataScr where you should have dataSrc.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Nice spotting @tangerine! Your ability to pick up typos never ceases to amaze me :)

    Allan

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    It's probably because I get so much practice on my own code....

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

    @allan.: base_url."/Admin/list", when put in the, index.php, <?=base_url + "/Admin/list"?> gives warning : A non-numeric value encountered. If I change the + to a point, the route http://localhost/new_web/Admin/listar works fine, I don't know how to do it in js, to check that.

    @tangerine. You're right, it's badly written, I fixed it, but there were no changes, everything remains the same.

    On the other hand, I am going to try another version of JQUERY, was that it?

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    On the other hand, I am going to try another version of JQUERY, was that it?

    No the jQuery version doesn't matter.

    Use the browser's network inspector to view the JSON response. Likely the response is not what Datatables supports or the use of ajax.dataSrc is pointing to the wrong data. Can you post a sample of the response here?

    See the ajax docs for more details.

    Kevin

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

    Despues de realizar los cambios de versiones da el siguiente error, y sigue sin mostrar los datos.
    TypeError no capturado: no se pueden leer las propiedades de undefined (leyendo 'estilo')
    en ee (tablas de datos.min.js:16:40103)
    en Jt (tablas de datos.min.js:16:32717)
    en t (tablas de datos.min.js:16:8587)
    en HTMLTableElement.<anónimo> (datatables.min.js:16:8673)
    en Function.each (jquery-3.6.0.min.js:2:3003)
    en S.fn.init.each (jquery-3.6.0.min.js:2:1481)
    en S.fn.init.w [como tabla de datos] (datatables.min.js:16:3564)
    en P.fn.DataTable (datatables.min.js:16:86687)
    en HTMLDocument.<anónimo> (admin.js:3:31)

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    edited April 2023

    After making the version changes it gives the following error, and still does not show the data.
    TypeError not caught: can't read properties of undefined (reading 'style')

    Please see my previous comments:

    Use the browser's network inspector to view the JSON response. Likely the response is not what Datatables supports or the use of ajax.dataSrc is pointing to the wrong data. Can you post a sample of the response here?

    See the ajax docs for more details.

    Kevin

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

    @kthorngren : Thanks kthorngren for your help, I did what was recommended and attached images with the result of the network, in response it returns all the source code.


  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    in response it returns all the source code.

    The source code for the base_url + "/Admin/listar", controller?

    If so, then it isn't being executed by whatever server you are using. That said, i don't see listar in the files listed for the page's requests there.

    Allan

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

    The code it shows is from admin.js.
    let tblAdmins;
    document.addEventListener("DOMContentLoaded", function(){
    tblAdmins = $('#tblAdmins').DataTable({
    ajax: {
    url: base_url+"/Admin/list",
    dataSrc: ""
    },
    columns: [
    {"data" : "id"},
    {"data" : "username"},
    {"data" : "name"},
    {"data" : "actions"},
    ]
    });
    })

    I don't know what to do

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Honestly, I think you are going to have to give me a link to the page here. Can you publish it somewhere?

    Allan

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0
    edited April 2023
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    I've sent an access request. It might give me enough information - I'm not sure. I really need to know what the list Ajax controller is returning, but your browser doesn't appear to be listing it in the list of requests, so I'm not convinced the DataTables code is even running.

    That doesn't make sense with the error messages above though which show DataTables is doing something.

    I honestly think I'll need a link to your page. I can look at the code, but I can't guarantee that I'll find anything.

    Allan

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

    OK thanks.
    The accesses are:
    User : admin
    Password: admin.

    I honestly think I'll need a link to your page.
    I still don't have a link to the page, I'm working on my PC's localhost

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    It still says I need access and I have to request access. I've just clicked the button to request access. There is no where I can enter a user name and password.

    I still don't have a link to the page, I'm working on my PC's localhost

    You'll likely have to put it somewhere I can access it in that case. I will look at the code and try to help, but its like phoning a car mechanic and saying "there is something wrong with my car's engine. No, I can't bring the car in".

    There is a reason why we ask for a test case in the forum rules :). I would have been able to diagnose the issue after your first post, three days ago, if you'd included a test case.

    Sorry, I know I probably sound a bit grumpy - I don't mean to be. I want to help, but at the moment I don't have enough information to do so!

    Allan

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

    Thank you so much. I already solved the problem, I really don't know what it was, because I went back to the base and started everything again and everything works fine now.
    Sorry for the inconvenience and Thank you very much.

  • ClaudioGSClaudioGS Posts: 22Questions: 0Answers: 0

    Thank you so much. I already solved the problem, I really don't know what it was, because I went back to the base and started everything again and everything works fine now.
    Sorry for the inconvenience and Thank you very much.

Sign In or Register to comment.