Unable to get Datatables to dynamically pull data from the server.

Unable to get Datatables to dynamically pull data from the server.

lovemlovem Posts: 1Questions: 0Answers: 0
edited July 2012 in DataTables 1.9
Debug link: http://debug.datatables.net/ucobic
Link showing failure: http://74.94.49.107/omnivore/index.php?report=test

I am trying to get Datatables to pull data via POST, though I would settle for GET at this point, from this URL http://74.94.49.107/omnivore/sqljson.php. At the moment, this script is dummied up to always return:

{"sEcho":null,"iTotalRecords":7,"iTotalDisplayRecords":7,"aaData":[["TS102","CentOS Linux release 6.0 (Final)"],["IRONMAN","Microsoft Windows 7 Professional"],["MLOVE6-10","Microsoft Windows 7 Professional"],["BEPPO","Microsoft Windows XP Professional"],["THEDARKKNIGHT","Microsoft Windows 7 Professional"],["CR2","Microsoft Windows 7 Home Premium"],["STORM","Microsoft Windows 7 Home Premium"]]}

sEcho is set to $_POST['sEcho'].
I have also tried to have the JSON output start with the aaData, and omit the three variables, same result.

The JSON output is valid per http://jsonlint.com/

I have tried to do this a few different ways based on the examples on this site and others.

Currently trying:
[code]
$.post(myurl,params, success,"json");

function success(json) {
$('#dataTable').dataTable( {
"bProcessing": true,
"aaData": json,
"bServerSide": true,
"sServerMethod": "POST",
"aoColumns": [
{"mDataProp": "hostname"},
{"mDataProp": "osname"},
]

});
}
[/code]

previously tried various permutations of this

[code]
$('#dataTable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sServerMethod": "POST",
"aoColumns": [
{"mDataProp": "hostname"},
{"mDataProp": "osname"},
]
"sAjaxSource": "http://74.94.49.107/omnivore/sqljson.php"
});
}

[/code]

Table code which hard coded in html/php
[code]



hostname
osname




Loading data from server




hostname
osname



[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You have a trailing comma in aoColumns which isn't going to help (IE will throw and error, other browsers will add an entry).

    You don't need to make the Ajax call yourself - DataTables will do it for you - see this example: http://datatables.net/release-datatables/examples/server_side/post.html

    I'd also suggest looking at the Javascript console in your browsers - I'm guessing there might be an error shown there at the moment.

    Allan
  • lovemlovem Posts: 1Questions: 0Answers: 0
    Thanks for the tips. Looks like I have bit to work with now. I think my biggest problem was a caching problem with my browser.

    One followup question, how do I set the values for my POST operation. I am looking to pass a the SQL statement that I need for the page I am loading. Is this possible, or do I have to create separate POST scripts for every report?
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    DataTables will automatically send parameters to the server with information about what data it is requesting ( http://datatables.net/usage/server-side ). If you want to add additional parameters, you can do so using fnServerParams .

    Allan
This discussion has been closed.