DataTables → Why your JSON might be invalid coming back from your database.
I was working on a Phalcon back-end that would retrieve and list user information for an admin panel. Below is the code:
When I use my DataTables code with the return data from the code above it worked totally fine.
Now I moved on to the projects portion of this website and when I tried to return the JSON I would get a :
I wracked my brain for a few hours on this I am ashamed to say and I couldn’t figure out why the same code would return some data but not others…until I looked at the difference in the data.
When I would var_dump() the JSON return, I noticed that a few of the objects simply said false. As I dug into the data in the database, I discovered that there were special characters, in this case a
instead of a
This is the reason why you get those � symbols instead of your simple quotes. Quote marks are usually the main culprit, and they are hard as hell to find.
Once I fixed these issues in the database and reloaded my page. My DataTables code and Phalcon code work flawlessly.
For those curious on how I was parsing the JSON in DataTables:
Hope this helps you.