do not get data via AJAX NOR Error -

do not get data via AJAX NOR Error -

bpmspacebpmspace Posts: 17Questions: 5Answers: 0

Hi

no clue what I'm doing wrong. I get an empty Table:

This is how my index.html looks like

<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>ICO Candidate world</title>
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://ico-cdn.pages.dev/font/font-awesome-4.7.0/css/font-awesome.min.css">
</head>
<body>

<table id="candidat" class="display" style="width:100%">
    <thead>
        <tr>
            <th>gender</th>
            <th>firstName</th>
            <th>lastName</th>
            <th>language</th>
            <th>mail</th>
            <th>cert</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>gender</th>
            <th>firstName</th>
            <th>lastName</th>
            <th>language</th>
            <th>mail</th>
            <th>cert</th>
        </tr>
    </tfoot>
</table>
</body>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
<script> $(document).ready(function () {
        $('candidat').DataTable({
            processing: true,
            ajax: 'result/lastresult.json',
            columns: [
                { data: 'gender' },
                { data: 'firstName' },
                { data: 'lastName' },
                { data: 'language' },
                { data: 'mail' },
                { data: 'cert' },
            ],
        });
    });
</script>
</html>

Ans this is my result/lastresult.json file ....

{
    "1": {
        "gender": "male",
        "firstName": "Fsdan",
        "lastName": "ifghuio",
        "language": "DE",
        "mail": [
            {
                "mail": "fxcxbbk@vacxvbcbc.de",
                "state": "active"
            }
        ],
        "cert": [
            {
                "name": "ICO ISMS 27001:2013 FOUNDATION"
            }
        ]
    },
    "2": {
        "gender": "male",
        "firstName": "dfsg",
        "lastName": "Ssdf",
        "language": "DE",
        "mail": [
            {
                "mail": "sdg.dsfg@sdfg.com",
                "state": "active"
            },
            {
                "mail": "sdfg.sdgf@sdf.ag",
                "state": "active"
            }
        ],
        "cert": [
            {
                "name": "ICO ISMS 27001:2013 FOUNDATION"
            },
            {
                "name": "ICO ISMS FOUNDATION according to TISAX"
            }
        ]
    },
    "count": 2,
    "runs": 5,
    "execution_time": 0.0020787676175435385
}

But the tableis empty when i call the index.html

I also Tried
* /result/lastresult.json
*. /result/lastresult.json
AND /result/lastresult.9953798. json which does not exists
Everything givs me an empty Table

any hints? thanks rob

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It's because the data is under an object where the key is different for each record, meaning that DataTables isn't able to find the data. Take a look at these two examples, here and here, they demonstrate the data format that's expected,

    Colin

Sign In or Register to comment.