Internalization JSON file doesn't load if I add header to each AJAX request
Internalization JSON file doesn't load if I add header to each AJAX request
IvanHalen
Posts: 2Questions: 1Answers: 0
Hello,
I'm adding a header to each AJAX request like this:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
}
});
But doing so, I'm not able to load the internalization JSON file for my language (https://cdn.datatables.net/plug-ins/1.10.16/i18n/Italian.json), getting this error:
Failed to load https://cdn.datatables.net/plug-ins/1.10.16/i18n/Italian.json: Request header field X-CSRF-TOKEN is not allowed by Access-Control-Allow-Headers in preflight response.
Any idea about how to solve this, keeping the CDN file? Or am I forced to swap to a local internalization file?
Thank you
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Yes, the CSRF token is not something that should be getting sent to any external site, so the CDN server is correctly rejecting it.
Currently you'd need to make a custom Ajax request to get the i18n information, or use local translation files.
Regards,
Allan