In Laravel getting this error CRSF token mismatch. While I will try to save data into the database it getting an error, data can’t save into the database.
How can I fix that?
I am following this code:
<script> $.ajax({ type: "POST", data: formData, contentType: false, cache: false, processData:false, url:base_url+"/save-data", success: function(res){ console.log(res); } }); </script>
Apply csrf meta tage in your page header:
<meta name="csrf-token" content="{{ csrf_token() }}">
Add those code in AJAX
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }
For example:
<script> $.ajax({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, type: "POST", data: formData, contentType: false, cache: false, processData:false, url:base_url+"/save-data", success: function(res){ console.log(res); } }); </script>
Question and answer is powered by AnsPress.io