Using AJAX (objects) as Datasource - error

Using AJAX (objects) as Datasource - error

AndersHPAndersHP Posts: 36Questions: 14Answers: 1

I'm using my ASP.Net Web Api project as AJAX datasource. But when the page loads, the first (and only) row of the table says "Loading..." infinitely even though it's not a huge data load.

Browser debugger tells me : "Uncaught TypeError: Cannot read property 'length' of undefined(anonymous function) "

Suggestions`?

Datatable is initialised like this:

var table = $('#table').DataTable( {
            "ajax": "http://localhost:50131/api/Values",
            "scrollX": true,
            "scrollY": "400px",
            "columns": [
                { "v_MetaData_CodeList": "CodeListIdentifier" },
                { "v_MetaData_CodeList": "CodeListName" },
                { "v_MetaData_CodeList": "CodeListTypeCode" },
                { "v_MetaData_CodeList": "CodeListTypeName" },
                { "v_MetaData_CodeList": "CreationDate" },
                { "v_MetaData_CodeList": "ApplicantIdentificationText" },
                { "v_MetaData_CodeList": "PurposeText" },
                { "v_MetaData_CodeList": "VersionIdentifier" },
                { "v_MetaData_CodeList": "VersionModificationText" },
                { "v_MetaData_CodeList": "VersionCreationDate" },
                { "v_MetaData_CodeList": "DescriptionText" },
                { "v_MetaData_CodeList": "CodeListLastUpdateDate" },
                { "v_MetaData_CodeList": "TaxonomyDescriptionText" },
                { "v_MetaData_CodeList": "ExpertIdentificationText" },
                { "v_MetaData_CodeList": "AdditionalDescriptionText" },
                { "v_MetaData_CodeList": "MetaDataLastUpdateDate" },
                { "v_MetaData_CodeList": "AdditionalFields" }
            ]
        } );

My html:

<table id="table" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>KodelisteNr</th>
            <th>KodelisteNavn</th>
            <th>KodelisteTypeKode</th>
            <th>KodelisteTypeNavn</th>
            <th>Oprettelsesdato</th>
            <th>Ansøger</th>
            <th>Formål</th>
            <th>Version</th>
            <th>Version Text</th>
            <th>Versionsoprettelsesdato</th>
            <th>Beskrivelse</th>
            <th>Sidste opdatering</th>
            <th>Taxonomibeskrivelse</th>
            <th>Ekspert</th>
            <th>Yderligere beskrivelse</th>
            <th>Metadata sidst opdateret</th>
            <th>Øvrige</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>KodelisteNr</th>
            <th>KodelisteNavn</th>
            <th>KodelisteTypeKode</th>
            <th>KodelisteTypeNavn</th>
            <th>Oprettelsesdato</th>
            <th>Ansøger</th>
            <th>Formål</th>
            <th>Version</th>
            <th>Version Text</th>
            <th>Versionsoprettelsesdato</th>
            <th>Beskrivelse</th>
            <th>Sidste opdatering</th>
            <th>Taxonomibeskrivelse</th>
            <th>Ekspert</th>
            <th>Yderligere beskrivelse</th>
            <th>Metadata sidst opdateret</th>
            <th>Øvrige</th>

        </tr>
    </tfoot>

</table>

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Can you link to a test case showing the issue (per the forum rules) please.

    Also, any errors shown in your browser's console?

    Allan

  • AndersHPAndersHP Posts: 36Questions: 14Answers: 1

    The reason was that the JSON needed be wrapped in a dictionary

    Thank

This discussion has been closed.