laravel中用ajax請求頁面時有時會出現(xiàn)419錯誤,這是因?yàn)闆]有csrf值
在頁面上添加
<meta name="csrf-token" content="{{ csrf_token() }}">
在頁面js中添加
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
參考:
https://docs.golaravel.com/docs/5.5/csrf/#csrf-x-csrf-token
Fabrizio Coltellaro
zvonimir duric
Coltric Properties