problem when init datatable using ajax to get server records with no records return
problem when init datatable using ajax to get server records with no records return
kevin liu
Posts: 4Questions: 2Answers: 0
I'm using datatable 1.11.5 and initialize a datatable using ajax to get server records to display.
There is a case that no records in the table, and so I return the JSON of "{data:[]}", and the datatable show a warning of "Invalid JSON response" and the datatable{} is suspended.
it seems that datatable plugin can't distinguish no record and invalid record.
I will get the ajax manually and set the data if records returned, or nothing if none record is returned.
This discussion has been closed.
Answers
Can you show me a debug trace of the table when it gets no data loaded please? Or a link to the page.
Thanks,
Allan
It's OK now when I remove the data: setting in datatables({data: xx}), I check the data return is [] or not , and use diffrent datatables({}) with/without data setting in the init function.
So, If data is [] or null can check in the datatables({}) is more convinient for the user.
Thanks.
I'm afraid I still don't actually know what the issue is. If you were getting "Invalid JSON response" then the server was returning invalid JSON. Without a test case though, I can't say what that is.
Allan