Server side - and server is not called

Server side - and server is not called

mbaasmbaas Posts: 67Questions: 24Answers: 1

I am trying to build a small sample for a colleague to show how easy it is to workl with server-side datasources.

Now, unfortunately it's looong time since I last did and I no longer have that code - so I'm really starting from scratch. Which is probably a good thing, because things have changed anyway.

However. I'm struggling getting things going:

my html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Datatables & ajax</title>
<link
href="https://cdn.datatables.net/v/dt/jq-3.7.0/dt-1.13.8/datatables.min.css"
rel="stylesheet">
<script
src="https://cdn.datatables.net/v/dt/jq-3.7.0/dt-1.13.8/datatables.min.js"></script>
</head>
<body>
<h1>Sample for datatables using ajax calls to get data</h1>
<table id="example"></table>
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable( {
serverSide: true,
processing: true,
ajax: {
//url: 'http://localhost:8080/datasource',
url: '/datasource',
datatype: 'json',
type: 'POST'
}
} );
});
</script>
</body>
</html>

The server runs on port 8080 and while it delivers the .html fine - developer tools' network analysis doesn't show anything going out and consequently my endpoint is not being called.

What am I missing?

This question has accepted answers - jump to:

Answers

  • mbaasmbaas Posts: 67Questions: 24Answers: 1
    edited January 14

    Eh, sorry - this wasn't put very well. The server isn't called because we first have an error:

    jQuery.Deferred exception: c[h[n][0]] is undefined I@https://cdn.datatables.net/v/dt/jq-3.7.0/dt-1.13.8/datatables.min.js:20:42223

    Which I find confusing - as I assumed I had reproduced the simple example.

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    My guess is that you haven't defined the header. You can either place the thead and corresponding th for each column in HTML or use columns.title to define the header. See the HTML requirements doc for details.

    Kevin

  • mbaasmbaas Posts: 67Questions: 24Answers: 1
    edited January 14

    Thank you - good idea, but adding one didn't help.

    updated code:

        <!DOCTYPE html>
        <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Datatables & ajax</title>
                <link
                    href="https://cdn.datatables.net/v/dt/jq-3.7.0/dt-1.13.8/datatables.min.css"
                    rel="stylesheet">
                <script
                    src="https://cdn.datatables.net/v/dt/jq-3.7.0/dt-1.13.8/datatables.min.js"></script>
            </head>
            <body>
                <h1>Sample for datatables using ajax calls to get data</h1>
                <table id="example">
                    <thead>
                        <tr>
                            <td>first</td>
                            <td>second</td>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
                <script type="text/javascript">
                    $(document).ready(function() {
                        $('#example').DataTable( {
                            serverSide: true,
                            processing: true,
                            ajax: {
                                //url: 'http://localhost:8080/datasource',
                                url: '/datasource',
                                datatype: 'json',
                                type: 'POST'
                            }
                        } );
                    });
                </script>
            </body>
        </html>
    
  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    You have the ajax.url option commented out. What happens if you uncomment it?

    Kevin

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    That looks like it should be making a POST request to /datasource. If it isn't, it suggests to me that there might be a Javascript error happening on the page. Is anything shown on the console? What does the browser's network inspector show as well?

    Allan

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    Oops you have two urls defined with one commented out. Sorry for the confusion.

    Kevin

  • mbaasmbaas Posts: 67Questions: 24Answers: 1
    edited January 15

    I'm sorry guys - I found the problem. Actually all is well, it's just that yours truly missed to enable debugging on the server! :(((

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    No worries. Thanks for the update and good to hear you have it working now.

    Allan

Sign In or Register to comment.