Datatable is not a function, cant recognize js

Datatable is not a function, cant recognize js

KorpinKorpin Posts: 2Questions: 1Answers: 0

First of all, I would like to say that I know this is a question that comes up quite often and has been discussed many times.
But despite that, I can not solve it ...

I think I have declared my sources with jquery first and then datatable but when I load the web page I always have the same error message:

Uncaught SyntaxError: Unexpected token { jQuery.Deferred exception: $ (...). DataTable is not a function TypeError: $ (...). DataTable is not a function at HTMLDocument. (https: // localhost: 44338 / Events: 87: 27) at l (https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29375) at c (https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js:2:29677) undefined

Here's a picture of the network:

Could you please help me to solve it?

Thx!

Answers

  • KorpinKorpin Posts: 2Questions: 1Answers: 0

    Just figured out that i forgot to put the code in my post...
    Here we are:

    @model IEnumerable<jak.formulaire.Models.Events>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
    <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
    
    @* Datatable of Events member *@
    <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Event name</th>
                <th>Status</th>
            </tr>
        </thead>
    </table>
    
    @section Scripts{
        <script>
            $(document).ready(function () {
                $('#example').DataTable();
            });
        </script>
    }
    
  • colincolin Posts: 15,232Questions: 1Answers: 2,594

    Hi @Korpin ,

    I'm not too familiar with this, but I suspect you need to bring lines 3-5 (the scripts and CSS inclusions) into the "@section Scripts", so between lines 17-18.

    Cheers,

    Colin

  • ReggieTheDogReggieTheDog Posts: 4Questions: 1Answers: 0

    @Korpin Did you ever get resolution to this issue? Am experiencing the same and have tried every possible combination. Very frustrating.

This discussion has been closed.