Are the Examples Correct? Exact Copy and Paste but why Error?
Are the Examples Correct? Exact Copy and Paste but why Error?
https://datatables.net/examples/ajax/deep.html
There has to be something wrong because I've copied and pasted these pages into a blank project just for this purpose and the reason for that is because JSON data isn't being loaded when I'm passing it within a real project. This copy and paste should work. When I try I get an alert telling me that I've got an invalid JSON response. But I'm using the folder structure data/objects_deep.txt as if I change that by removing data, all I get is a loading so the file is obviously getting read...
Ok so I'm getting invalid JSON but how is that possible when it's and exact copy of JSON from DataTable's own example? I've quadruple checked that every single character is being selected, very easy. I'd load all this up in JSFiddle and I tried but I don't see where I can add the JSON file and no matter what, all I would be showing anyone is literally exact copies of DataTable's example.
So how is it possible that this does not work and I'm being told that the JSON from the example is invalid?
Thank you.
Answers
Please see the response in the other thread where you have asked the same question.
As tangerine mentioned we would need to see your code since the example you linked to works. I did copy and paste the example's ajax data and JS code here:
http://live.datatables.net/vufibetu/1/edit
It does work. However, like you mentioned, sending an ajax request for the data is problematic if its not hosted somewhere. So I pasted the JSON data into a variable and used
data
to get the data instead of an ajax request.Did you follow the steps in the tech note link in the Invalid JSON error alert you received?
https://datatables.net/manual/tech-notes/1
If so what did you find?
Kevin
I posted a comment but it disappeared after clicking post and nothing showed up...
Here is the HTML within the HTML file. The only modifications were that I removed the inner table tags after trying with them. I also tried CDN's and hard files in different places. The only modification I made was changing the "data" folder to "Data" with a capital 'D'. I also posted the contents of the .txt file but it was too long. That is an exact copy from the AJAX tab with zero modification in a file name the exact same. If it helps I can share that file from OneDrive.
<!DOCTYPE html>
<html>
<head>
<link href="jquery.dataTables.min" type="text/css"/>
<script src="jquery-3.2.1.min.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js "></script>
<script>
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"ajax": "Data/objects_deep.txt",
"columns": [
{ "data": "name" },
{ "data": "hr.position" },
{ "data": "contact.0" },
{ "data": "contact.1" },
{ "data": "hr.start_date" },
{ "data": "hr.salary" }
]
} );
} );
</script>
</head>
<body>
<table width="100%" class="display" id="example" cellspacing="0">
</table>
</body>
</html>
And yes I did check the browser debugger and am shown no errors or warnings.
It would be helpful if you can use Markdown to help format your code. I suspect the problem is this:
"ajax": "Data/objects_deep.txt"
You need to have
objects_deep.txt
on a web server accessible to you locally. Do you have this file on your server?This is why I took that data and put into a variable in my example.
Kevin
Thank you, Kevin I will try it out. No I don't have it on a web server. I will look at your example and try it that way as well. I will get back to you.
I can use the markdown to format code from now on. I would have to start with but didn't realize.