I had the same problem. Try to put an include CSRF tag in your meta
like so:
<meta name="csrf-token" content="{{ csrf_token() }}" />
And read it in your ajax code like so:
<script type="text/javascript"> $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); </script>Last Update
Please modify your url
variable like so:
jQuery.ajax({ type: "POST", url: '/my-route'+'?_token=' + '{{ csrf_token() }}', data: data, success: function() { console.log("A"); } });
Try This
var formData = new FormData(); formData.append("_token", "{{ csrf_token() }}"); $.ajax({ headers: { 'X-CSRF-TOKEN': "{{ csrf_token() }}" }, url: 'save_search', data: formData, processData: false, type: 'POST', success: function ( data ) { alert( data ); } });
I encountered an issue with my Laravel 8 where I noticed that the token was being sent in the URL through my AJAX request and the URL was correct. However, despite this, I was still receiving an error. Upon further investigation, I realized that I had changed the value of 'same_site'
in my session.php
file to "none".
After changing it back to 'same_site' => "lax"
, I was able to resolve the issue.