Quindi so che questo è un problema popolare e ho letto tutte le domande simili qui su Stackoverflow e altri siti (incluso il sito di dati).DataTable: impossibile leggere la proprietà 'length' di undefined
Per chiarire che sto usando
- PHP Codeigniter
- Materliazecss
Inoltre ho ricontrollato e fatto in modo che sono riuscito a ricevere correttamente l'array JSON come segue: (Si può controlla anche su http://www.jsoneditoronline.org/)
[{"name_en":"hello","phone":"55555555","email":"a.shouman","facebook":"https:\/\/www.facebook.com"},{"name_en":"Mahfouz","phone":"00000000","email":"m.mahfouz","facebook":null},{"name_en":"Abdelrahman","phone":"55555555","email":"a.shouman","facebook":"https:\/\/www.facebook.com"},{"name_en":"ayman test","phone":"55554444","email":"a.shouman","facebook":"https:\/\/www.facebook.com"},{"name_en":"Abdelrahman Mossad Shouman Bootstrap","phone":"12345678","email":"[email protected]","facebook":"https:\/\/www.facebook.com"},{"name_en":"Abdelrahman Mossad Shouman Bootstrap","phone":"12345678","email":"[email protected]","facebook":"https:\/\/www.facebook.co"},{"name_en":"a.sharara","phone":"00000000","email":"a.sharara","facebook":""}]
Quindi la mia h tml Table è come seguendo
<table id="customer_table">
<thead>
<tr>
<th>Name</th>
<th>Contact</th>
<th>Email</th>
<th>Facebook</th>
</tr>
</thead>
</table>
E qui è la mia funzione document.ready
$(document).ready(function(){
//$('#customer_table').DataTable();
$('#customer_table').DataTable({
"ajax": 'json',
"dataSrc": "",
"columns": [
{ "data": "email" },
{ "data": "facebook" },
{ "data": "name_en" },
{ "data": "phone" }
]
});
});
L'errore che sto ottenendo è questo
Uncaught TypeError: Cannot read property 'length' of undefined
questo è vero, ma senza senso –