Can't get DataTables ajax call to work

前端 未结 1 1378
你的背包
你的背包 2021-01-27 06:55

I\'m trying to figure out how to use the ajax option in DataTables 1.10. For the life of me, I cannot figure out how it works.

My server-side request, when queried, resp

相关标签:
1条回答
  • 2021-01-27 07:37
    • Option dataSrc should be a sub-property of ajax option.
    • There is no need to specify columns if data elements appear in sequential order
    • Your JSON response appears to be invalid. Correct response should be

      {
        "success": true,
        "history": [
          ["John Doe","02 Mar 2016","Area 1","Value A","May 15","200"],
          ["Jane Doe","29 Feb 2016","Area 2","Value B","Apr 15","100"]
        ]
      }
      

    Corrected code is shown below:

    $("#history-table").DataTable({
        'ajax': {
            'url': "/some-path-here",
            'type': "POST",
            'data': { 'pid': pID },
            'dataSrc': 'history'
        },
        'autoWidth': false,
        'lengthChange': false,
        'ordering': false,
        'pageLength': 50
    });
    

    See this jsFiddle for code and demonstration.

    0 讨论(0)
提交回复
热议问题