Define {{ csrf_token }}
as a global variable on your HTML page in the tag script
as a global variable as such: -
var generated_csrf_token = "{{ csrf_token }}";
And then in your .js file call it,
headers: {'X-CSRFToken': generated_csrf_token},
But make sure you put the AJAX call in the document ready func in $(document).ready(function () {***here***}
This way you can access it with a name generated_csrf_token
in any js file.
Hope this helps :-)
source
share