[RFE] Example code improvement (?) suggestion / bugfix
[RFE] Example code improvement (?) suggestion / bugfix
Hello,
I believe the server-side processing example listed at http://datatables.net/examples/server_side/server_side.html contains an error in the code.
The addslashes() calls around each entry in the $sOutput string will escape single quotes ( ' ) into escaped quotes ( \' ), but these will not be properly handled by the JSON parser and will thus give an error. This can be fixed either by using str_replace to replace any occurrences of escaped quotes with single quotes after $sOutput has been finalized, or possibly by using PHP's addcslashes() function to escape specific symbols (I haven't tested this latter approach, but I believe it might be cleaner).
Another option might be to use PHP's built-in json_encode function.
I believe the server-side processing example listed at http://datatables.net/examples/server_side/server_side.html contains an error in the code.
The addslashes() calls around each entry in the $sOutput string will escape single quotes ( ' ) into escaped quotes ( \' ), but these will not be properly handled by the JSON parser and will thus give an error. This can be fixed either by using str_replace to replace any occurrences of escaped quotes with single quotes after $sOutput has been finalized, or possibly by using PHP's addcslashes() function to escape specific symbols (I haven't tested this latter approach, but I believe it might be cleaner).
Another option might be to use PHP's built-in json_encode function.
This discussion has been closed.
Replies
Or do you mean to say that if your data itself has a single quote in it? I have to admit, my data set does not, so I'm not sure if it would fail or not.
Allan