It has been 1238 days since the last update, the content of the article may be outdated.

Laravel csrf token mismatch for ajax POST Request

在 laravel 裡使用 ajax post 方法遇到 CSRF Token 不符問題

In header

<meta name="csrf-token" content="{{ csrf_token() }}" />

In script

javascript
<script type="text/javascript">
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>