Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

javascript - How do I fix error on paging using Datatables and server side data source?

I'm using the datatables framework described here:

https://datatables.net/examples/server_side/simple.html

I'm able to get the example defined at this url to work on the initial page load. However the sort and page buttons do not work. When the button is pressed the ajax call seems to be called: the server returns a json string representing the data (it it the same string shown in the ajax tab). The call seems to return the data to the page (I can see the json string in the response using Chrome tools). However, the table does not seem to refresh and the "Processing..." window never clears.

This is what the javascript in the page looks like:

<head>
    <script>
        $(document).ready(function() {
            $('#example').DataTable( {
                "processing": true,
                "serverSide": true,
                "ajax": "${home}/Forward?actionClass=serverexample.ServerExampleAction"
            } );
        } );
    </script>
</head>

What am I doing wrong here?

--- EDIT ------------

Also, is there a way I can debug this (e.g. add an alert to see what code is actually executing, I'm not using the minimized js, I'm using datatables.js).

The JSON returned by the query is this:

{
  "draw": 10,
  "recordsTotal": 57,
  "recordsFiltered": 57,
  "data": [
    [
      "Caesar",
      "Vance",
      "Pre-Sales Support",
      "New York",
      "12th Dec 11",
      "$106,450"
    ],
    [
      "Cara",
      "Stevens",
      "Sales Assistant",
      "New York",
      "6th Dec 11",
      "$145,600"
    ],
    [
      "Cedric",
      "Kelly",
      "Senior Javascript Developer",
      "Edinburgh",
      "29th Mar 12",
      "$433,060"
    ]
  ]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...