Server side - and server is not called
Server side - and server is not called
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
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.
My guess is that you haven't defined the header. You can either place the
thead
and correspondingth
for each column in HTML or usecolumns.title
to define the header. See the HTML requirements doc for details.Kevin
Thank you - good idea, but adding one didn't help.
updated code:
You have the
ajax.url
option commented out. What happens if you uncomment it?Kevin
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
Oops you have two urls defined with one commented out. Sorry for the confusion.
Kevin
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! ((
No worries. Thanks for the update and good to hear you have it working now.
Allan