Created
December 27, 2019 10:22
-
-
Save Enigama/7b60f1e586dad5e5e78e7cfdea7a0699 to your computer and use it in GitHub Desktop.
request header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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