Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


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



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,

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



Hi,

May I know which Metronic version are you using?

Regards


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(