In header
<meta name="csrf-token" content="{{ csrf_token() }}" />
In script
<script type="text/javascript">
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
$.ajax({
headers: {
'X-CSRF-TOKEN': "{{csrf_token()}}",
},
url : "{{route('')}}",
type : "GET",
success : function(response){
}
});
<form method="POST" action="/profile">
@csrf
<!-- Equivalent to... -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
</form>
<!-- Add this to header -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<!-- Add this to script -->
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
"_token": "{{ csrf_token() }}",
"_token": "{{ csrf_token() }}",
$.ajax({
url: '/postAjaxUrl',
type: 'POST',
dataType: 'json',
data: {user_id: 10},
success: function(response) {
console.log(response);
},
beforeSend: function (request) {
return request.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content'));
}
});