How to add CSRF_TOKEN in KTDatatable?
Hi,
I need to POST with KTDatatable, but my backend is expecting a CSRF_TOKEN. How do I include this?
```
ReferenceError: Can't find variable: CSRF_TOKEN
```
Replies (5)
Hi,
May I know which Metronic version are you using?
Regards
Hi,
In the data.source.read config, could you please try to add _token value?
read: {
url: HOST_URL + '/api/datatables/demos/orders.php',
data: {
_token: 'token-value'
}
},
Thanks
does not work for me:
var datatable = $("#table").KTDatatable({
data: {
type: "remote",
source: {
read: {
url: "/myurl/",
data: {
_token: CSRF_TOKEN,
},
method: "POST",
map: function (raw) {
var dataSet = raw;
if (typeof raw.data !== "undefined") {
dataSet = raw.data;
}
return dataSet;
},
},
},
Hi
Actually, we have stopped support for the KTDatatable. In Metronic v8+, the Datatatables.net plugin is fully used which has more great features. It would be good if you could consider moving forward to use Datatatables.net instead of KTDatatable.
Datatables.net plugin has this feature to support CSRF_TOKEN and POST methods.
Thanks