DataTables do not load AJAX data on MacOS?

DataTables do not load AJAX data on MacOS?

sergiy@networkcredo.netsergiy@networkcredo.net Posts: 2Questions: 1Answers: 0
edited November 2023 in Free community support

No Console errors, no errors in DataTables debugger.
Am I missing something?

<!DOCTYPE html><html lang="en">
    <head>
        <title>JavaScript example</title>
        <meta charSet="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css"/>
        <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
        <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    </head>
    <body>

        <script>
    
    new DataTable('#example', {
        "ajaxSource": 'data/objects_deep.txt',
    columns: [
        { data: 'name' },
        { data: 'hr.position' },
        { data: 'contact.0' },
        { data: 'contact.1' },
        { data: 'hr.start_date' },
        { data: 'hr.salary' }
    ],
    processing: true
});
        </script>
<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>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Extn.</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
</table>

    </body>
</html>

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • kthorngrenkthorngren Posts: 20,800Questions: 26Answers: 4,862

    There isn't anything obvious in your code snippet. You are using the legacy (ajaxSource) form of the ajax option. See the 1.9 to 1.10 conversion guide for more info. I don't thnk changing to ajax will make a difference.

    Make sure your webserver can can resolve the path to data/objects_deep.txt.

    Use the browser's network inspector tool to see the XHR request and response. Let us know what you find. Can you post a link to your page or a test case repliacting the issue so we can help debug?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • sergiy@networkcredo.netsergiy@networkcredo.net Posts: 2Questions: 1Answers: 0

    Well, this is embracing...
    I forgot that the code needs to run inside of
    $(document).ready(function(){ /code here/ })
    And then there is a CORS block

  • allanallan Posts: 62,522Questions: 1Answers: 10,272 Site admin

    The other option is to stick the script for the loading of the table at the end of the body. Good to hear you got that fixed though. The CORS issue would require a change to the headers sent by the server.

    Allan

Sign In or Register to comment.