Valid JSON returning as invalid
Valid JSON returning as invalid
Hi, I can't link to the page showing the problem because I'm using DataTables.js in the admin console of a Wordpress site.
Here's the DataTables debugger link: http://debug.datatables.net/emiwug
Here's the problem:
I get the DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
error everytime I try and load the page. However, when viewing the source of the document, I get as follows: https://gist.github.com/broskees/9a8c17911f3a6dcfb2fef1d926c76f65
I know that's a lot of code, but look specifically between lines 211 to 228, and also lines 858 to 1067.
In that, you can see that the JSON is definitely properly validated. I even validated it via https://jsonlint.com/
Help would be greatly appreciated.
Thank you!
Answers
If you go to the debugger link, click on the
Tables
tab then click onServer interaction
you will see the JSON response Datatables doesn't like. Its a bit strange that it shows your full page code.When using the
ajax
option the expectation is that the data will be fetched from a server. In your case you are simply defining it. Since you aren't fetching it you will want to treat it like Javascript sourced data like this example:https://datatables.net/examples/data_sources/js_array.html
Basically you have:
Where
data
is inside theajax
option. I think it will work if you remove the 3 lines I noted, essentially removing theoption ajax
option config and leaving just thedata
option. This should look like the array of objects example of thedata
docs.Kevin
I'm being told that my JSON is invalid when I'm using exact copies of DataTable.net's own example. Just create a new blank project which is very small and copy and paste the example from the link below, which is DataTable's provided "working" example, and see how it's claiming that the JSON is invalid. How is this possible?
https://datatables.net/examples/ajax/deep.html
The reason I'm doing this is because I'm passing valid JSON data to a DataTable in another project and it's loading nothing. The JSON is an exact match of the syntax shown in the example. I figured I'd make sure the example was working and low and behold, it doesn't work. I even did a second project and typed everything by hand just to make sure Windows wasn't copying and pasting incorrectly by some fluke chance but still the same thing.
@danielj210 , you should really start a new thread rather than hi-jacking @jrobtz's thread.
Also it is more likely that you will get some assistance if you present your code. It seems unlikely that you have made an exact copy of the example, since the example works.
He got an answer. Hijacking? I was adding to an issue.
@danielj210 - The anti-spam mucking around with your account is frustrating - sorry about this, its getting me in a muddle never mind anything else. I've added a reply to your other thread here now that it has been approved.
If you are still having problems with it, let's carry on the discussion there rather than splitting it between two threads. If you are having problems, perhaps you can run the debugger on the page and let me know the debug code generated.
Allan