DataTables warning: table id=example - Invalid JSON response.
DataTables warning: table id=example - Invalid JSON response.
kkvbsuresh
Posts: 32Questions: 6Answers: 0
DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
URL - http://tabledata.byethost3.com/d-table.html
html
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">
<script>
$(document).ready(function () {
$('#example').DataTable({
ajax: 'data-arrays.txt',
deferRender: true,
});
});
</script>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
</table>
</body>
ajax
{
"data": [
[
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800"
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
]
]
}
Any good help to solve the above ?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
all these scripts are added at the URL properly in the head.
src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"
src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"
$(document).ready(function () {
$('#example').DataTable({
ajax: 'data-arrays.txt',
deferRender: true,
});
});
Have you followed the steps in the technical notes linked to in the error? That'll be the place to start. If so, what did you find?
Colin
I see there is a link to the page showing the issue - thanks for providing that.
I've taken a look and there is something very odd happening with your text file. If I load it using Firefox, I can see the data. However, if I use wget or curl, the server isn't sending anything at all:
Downloading the file from Firefox, saving and then viewing with a hex editor I can see that the file starts with:
That's a UTF-8 BOM. Try removing it and I expect it will then work.
Allan
save the file (d-table.html) as with ANSI Mode instead of UTF-8 and shown the same error as
'DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1'
don't know more about the issue.
what needs to do ?
what are the file extensions can use instead of '.txt' at ajax: 'data-arrays.txt', to solve the issue ?
Use any extension you want, or none at all - it entirely depends upon your HTTP server.
I'd suggest using a Hex editor on your file to check for the BOM and remove it.
Allan
Don't have that much knowledge or skill. Can you send it to the email 'kkvbsuresh@live.com' a working sample for ajax: 'data-arrays.txt' ?
E-mail sent
Allan
cheers for every help.