Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

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
```


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

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 happy

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


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(