Intermittent issue with sort and search.
Intermittent issue with sort and search.
Good evening,
I have been experiencing a weird intermittent error when sorting or searching:
SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at jquery.min.js:2
at l (jquery.min.js:2)
at XMLHttpRequest.<anonymous> (jquery.min.js:2)
The error is caused by the returned JSON string being empty. However this issue only happens from time to time when sorting or searching. (Usually when we input too fast or click several times on the sort column.)
Link to sandbox demo: https://eco.tinoco.ca/
Using datatables version 1.10.20 with bootstrap integration
Datatables Client Side: https://pastebin.com/a6fkK6g2
Datatables Server Side: https://pastebin.com/RiDdZLV1
Server AJAX request response: https://pastebin.com/TwP2Rd3J
Any help is appreciated.
Answers
Just found out that it works perfectly fine in the localhost environment. The issue only occurs on hosted environment.
The error is caused by an empty response from the server. If it's fine on localhost, but not on hosted, the problem is likely to be the permissions to access the database, or something else that is stopping the script from running the queries. Try running the PHP script on the server and see what happens there.
Colin
It does run on the server, and database credentials are valid (see demo). Do you have examples for the following: "something else that is stopping the script from running the queries."?
The demo is just showing an empty response from the server, which is why I suggested just running the PHP script from the command line to see what that returns. Other examples are permissions of the script, using the correct address for the database server - things that can get left with the details for the localhost and not updated for production.
Colin
I have verified connection, file permission, call urls, debugged server side processing. The only thing I can think of is a memory issue or a version bug. However, it is only 43k records, datatables should not have any problem.
Found the following also happen intermittently;
https://prnt.sc/15g7vcl
Have you tried running the PHP script from the command line as I suggested?
Colin
Yes I did, however after lots of debugging I found the issue.
$db->exec("set names utf8"); must be added after the connection. Thank you to @CsibeGYILOK
https://datatables.net/forums/discussion/21242/invalid-json-response-when-adding-some-utf-8-characters
Glad all sorted, thanks for reporting back
Colin