I'm trying to use the DataTables library for Jquery to POST some simple data to a controller which is a SQL query. This query will return JSON and I will go on my merry way and then do what I will with the data.
I am having no problems with this when using built in jquery AJAX. Here is the working code:
$.post('/rx/dostuff', {fromDate: from_date, toDate: to_date}, function(data){
var dataObject = JSON.parse(data);
if(data !== "[]"){
$("#display_area").empty();
$("#display_area").append("<div> " + ...
blah blah blah
So this works great, I POST the from_date and the to_date, and I can see in the Network Params tab that it is being sent as
fromDate: 02/01/2016
toDate: 02/24/2016
which my PHP controller picks up, I do some statement binding to keep it safe, and boom, my results are returned to me JSON encoded.
When I try to do this using the DataTables library, my params end up being sent like this:
fromDate=02%2F01%2F2016&toDate=02%2F24%2F2016
PHP raises hell, and throws a warning that I am missing argument 1 for my controller.
My question is, why is DataTables sending the params like this? Have I malformed the way that it is meant to be sent?
Here is my DataTables AJAX code:
$('#dataTable').DataTable({
ajax: {
url: "/rx/dostuff",
type: "POST",
contentType: "application/json",
data: {
"fromDate": from_date,
"toDate": to_date
}
},
columns: [
{ data: 'col'},
{ data: 'col'},
{ data: 'col'},
{ data: 'col'}
]
});
Any help is much appreciated!