Unable to get Datatables to dynamically pull data from the server.
Unable to get Datatables to dynamically pull data from the server.
lovem
Posts: 1Questions: 0Answers: 0
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]
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]
This discussion has been closed.
Replies
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
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?
Allan