DataTables warning: table id=example - Invalid JSON response.

DataTables warning: table id=example - Invalid JSON response.

kkvbsureshkkvbsuresh Posts: 32Questions: 6Answers: 0
edited January 2023 in Free community support

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

  • kkvbsureshkkvbsuresh Posts: 32Questions: 6Answers: 0

    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,
        });
    });

  • colincolin Posts: 15,146Questions: 1Answers: 2,586

    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

  • allanallan Posts: 61,734Questions: 1Answers: 10,110 Site admin

    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:

    → curl -i http://tabledata.byethost3.com/data-arrays.txt?_=1673267500630
    curl: (52) Empty reply from server
    

    Downloading the file from Firefox, saving and then viewing with a hex editor I can see that the file starts with:

    efbbbf
    

    That's a UTF-8 BOM. Try removing it and I expect it will then work.

    Allan

  • kkvbsureshkkvbsuresh Posts: 32Questions: 6Answers: 0

    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 ?

  • kkvbsureshkkvbsuresh Posts: 32Questions: 6Answers: 0
    $(document).ready(function () { $('#example').DataTable({ ajax: 'data-arrays.txt', deferRender: true, }); });

    what are the file extensions can use instead of '.txt' at ajax: 'data-arrays.txt', to solve the issue ?

  • allanallan Posts: 61,734Questions: 1Answers: 10,110 Site admin

    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

  • kkvbsureshkkvbsuresh Posts: 32Questions: 6Answers: 0

    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' ?

  • allanallan Posts: 61,734Questions: 1Answers: 10,110 Site admin

    E-mail sent :)

    Allan

  • kkvbsureshkkvbsuresh Posts: 32Questions: 6Answers: 0

    cheers for every help.

Sign In or Register to comment.