When attempting to make a datatable ajax request, I encountered an unexpected result on the server side. The console is logging the data as shown below:
[Object: null prototype] {
draw: '1',
'columns[0][data]': 'no',
'columns[0][name]': '',
'columns[0][searchable]': 'true',
'columns[0][orderable]': 'true',
'columns[0][search][value]': '',
'columns[0][search][regex]': 'false',
'columns[1][data]': 'projectName',
...
'search[value]': '',
'search[regex]': 'false',
projectName: ''
}
The client-side js function responsible for this behavior is outlined below:
function getSettingInfo() {
$('#settingInfo').show();
$('#settingInfo').DataTable({
destroy: true,
processing: true,
serverSide: true,
searching: false,
ajax: {
type: 'POST',
url: '/setting/getSettingInfo',
data: function(d) {
d.projectName = '';
}
},
iDisplayLength: 10,
order: [[0, 'desc']],
pagingType: 'simple_numbers',
columnDefs: [
{ className: "dt-head-center", targets: [0, 1, 2, 3, 4] },
{ className: "dt-center", targets: [0, 1, 2, 3, 4] },
],
columns: [
{ data : "no", width : '6%'},
{ data : "name", width : '13%'},
{ data : "key", width : '17%'},
{ data : "description", width : '32%'},
{ data : "use", width : '32%'}
]
});
}
In addition, here is the server router's js code:
router.post('/getSettingInfo', async function (req, res) {
let param = req.body;
console.log('\n\nparam', param);
}
I am facing a dilemma where the request object is being interpreted as a null object. It is causing param.order in my last javascript file to be logged as undefined.