Skip to content

Instantly share code, notes, and snippets.

@Enigama
Created December 27, 2019 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Enigama/7b60f1e586dad5e5e78e7cfdea7a0699 to your computer and use it in GitHub Desktop.
Save Enigama/7b60f1e586dad5e5e78e7cfdea7a0699 to your computer and use it in GitHub Desktop.
request header
/*axios*/
const setUpCSRFToken = () => {
let token = document.head.querySelector('meta[name="csrf-token"]');
axios.defaults.headers.common = {
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-TOKEN': token.content
};
};
/*ajax*/
const setUpCSRFToken = () => {
const token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': token.content,
},
});
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment