DataTables Submit data as JSON in the request body
DataTables Submit data as JSON in the request body
According to the API manual : https://datatables.net/reference/option/ajax.data, I should able to send a AJAX get request with data as JSON in the request body.
However, after I follow the same way, my data is always sent out in the request headers instead of the request body.
table = $('#table').DataTable({
dom : 'Tfrtip',
ajax : {
"url" : 'webapi/gpsinputadmin',
"contentType" : "application/json",
"data" : function(d) {
d.data = getInputData();
return JSON.stringify(d.data);
}
}
}
Is there anything wrong in my code?
Answers
You need to send it a POST if you want it in the request body, since GET doesn't have one. I'll update the example. Here is a little test case: http://live.datatables.net/nurakipi/1/edit .
Allan
If GET method can't send data in request body, then the description in the manual here is abit misleading. https://datatables.net/reference/option/ajax.data
Below is the example written in the manual.
Submit data as JSON in the request body:
Agreed! I've committed a fix and will deploy it to the site with the next update.
Thanks,
Allan