datatable with empty AJAX response
datatable with empty AJAX response
I have a datatable that pulls data from the server using AJAX Different parameters (JSON) are passed to the datatable using values posted from html select boxes. The parameters are parsed using business logic and respective JSON files are generated and sent back to the datatable.
This works fine until the business logic generates some output. When the SQL statement finds no data for some parameter combination the JSON returned back in NULL. In this case the datatable should clear up existing data and show up some message like "Records not found....", unfortunately this does't happen. The datatable stays with previous data and an error pops up in the console window ..
datatables.min.js:76 Uncaught TypeError: Cannot read property 'error' of null
The debug code for the datatable that I am working with is : http://debug.datatables.net/eterel
Any sort of idea / assistance would be highly appreciated.
Replies
An empty value (string) is not valid JSON is the issue here. You would need to return
[]
rather than an empty string. i.e. an array that has no data in it.Allan
And that's a BOOM! Working Perfectly
Many thanks @Allan finding out time out of your busy schedule.
I suffered lots. As an option, I was doing UNION ALL with empty records alongside the main SQL query to make sure something is always returned.
You're a star
Awesome - great to hear that worked. Thanks for posting back!
Allan