"Unexpected token" and "DataTable is not a function"
"Unexpected token" and "DataTable is not a function"
I'm having two issues when initialising DataTable. Both show on the console:
The "unexpected token" one is confusing to me, because the error seems to be within datatables.bundle.js, and I have not changed the code in it.
Here's a screenshot of the file's info, just in case:
I have included datatables.bundle.js before the calling of DataTable()
The jQuery library is not loaded more than once.
I am using Metronic, and I'm following instructions as seen here: https://preview.keenthemes.com/html/metronic/docs/general/datatables/overview
and here:
https://preview.keenthemes.com/html/metronic/docs/general/datatables/basic
May someone help me with this?
Thank you.
Answers
More info: The website with the error is running locally and is being developed with Razor for ASP.NET Core
Its hard to say what the problem might be without seeing the issue. Is it possible to post a link to your page or test case showing the issue?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
The
Unexpected token ')'
error seems to be coming from an Ajax request. Its hard to say what code is causing the error since it appears to be compiled code. Since you are using$("#kt_datatable_zero_configuration").DataTable();
to initialize an HTML table then there is no Ajax request from Datatables. I would take a look at the browser's network inspector to see the Ajax response that is causing the error. You can use jsonlint to test the JSON response.The
DataTable is not a function
might be due to the load order or an error loading thedatatables.bundle.js
library. It could a build problem with the Gulp process. It might be caused as a result of the above error. I've seen this error if jquery.js is loaded more than once. You can find threads on this forum with that error - maybe you will find other troubleshooting assistance.Let us know what you find.
Kevin