Ashish Singh Ashish Singh - 1 year ago 401
jQuery Question

Laravel csrf token mismatch for ajax POST Request

I am trying to delete data from database via ajax.


@foreach($a as $lis)
//some code
<a href="#" class="delteadd" id="{{$lis['id']}}">Delete</a>
//click action perform on this link

My ajax code:

$('body').on('click', '.delteadd', function (e) {
//alert('am i here');
if (confirm('Are you sure you want to Delete Ad ?')) {
var id = $(this).attr('id');
method: "POST",
url: "{{url()}}/delteadd",
}).done(function( msg ) {
if(msg.error == 0){
} else {
return false;

This is my query to fetch data from database...

$a = Test::with('hitsCount')->where('userid', $id)->get()->toArray();

But when i click on Delete link data not deleted and show csrf_token mismatch...

Answer Source

You have to add data in your ajax request. I hope so it will be work.

data: {
        "_token": "{{ csrf_token() }}",
        "id": id
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download