Intermittent issue with sort and search.

Intermittent issue with sort and search.

IrvinTLIrvinTL Posts: 8Questions: 2Answers: 0

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

  • IrvinTLIrvinTL Posts: 8Questions: 2Answers: 0

    Just found out that it works perfectly fine in the localhost environment. The issue only occurs on hosted environment.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • IrvinTLIrvinTL Posts: 8Questions: 2Answers: 0

    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."?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • IrvinTLIrvinTL Posts: 8Questions: 2Answers: 0

    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.

  • IrvinTLIrvinTL Posts: 8Questions: 2Answers: 0

    Found the following also happen intermittently;

    https://prnt.sc/15g7vcl

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Have you tried running the PHP script from the command line as I suggested?

    Colin

  • IrvinTLIrvinTL Posts: 8Questions: 2Answers: 0

    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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Glad all sorted, thanks for reporting back

    Colin

Sign In or Register to comment.