Send CSRF token with datatable ajax
Send CSRF token with datatable ajax
Vitaliy
Posts: 8Questions: 0Answers: 0
$('#invoices').dataTable({
"searchHighlight": true,
"order": [[ 0, "desc" ]],
"serverSide": true,
"ajax": {
type: "POST",
data:{
'request':'get_users_invoices',
'csrf_token':$('meta[name=csrf_token]').attr("content")
},
dataSrc: function ( json ) {
if(json.csrf_token !== undefined) $('meta[name=csrf_token]').attr("content", json.csrf_token);
return json.data;
}
}
.....................
When the page is loaded, the table works (token send successfully), the new token comes in the answer, but upon transition to other page, a token isn't sent, it seems to me at change of the page ajax doesn't sent
This discussion has been closed.
Replies
if remove check of CSRF on the server side, the table works perfectly
Can you link to the page showing the issue please.
Allan
sorry but i I work on localhost
server-side part
class
CSRF system works perfectly and where a problem I found but how to solve I don't know
At change of the page using previous request, with an old key which is already not present, but a code of
is used, receives a right key
perhaps the request is cached?
this CSRF system perfectly works with other ajax based functions, but i have problem only with datatables
https://datatables.net/examples/server_side/pipeline.html
I think its my problem but how to solve I don't know)
Oh you are using pipelining? That wasn't clear from your original post.
If so you need to modify the pipeline code, where it makes the
$.ajax
call to include your token.Allan
Now i dont use it, but:
I found the solution, instead of regular request, I decided to use a full caching of all pages. And the last question, than badly full caching (what number of records is maximum)?
my original problem(im still interested in it)
first request, request with next params:
success response
second page, second response
error response, token = 2222, but in sended request csrf_token = 1111
and i cant understand why ;(
Without a test case, I'm afraid there is very little that is can do to offer any help.
All I can say is that the code above will send
1111
as the csrf token, since that is the value assigned to that parameter.Allan