csrf mismatch laravel 8 Fixed

    By: Thad Mertz
    3 years ago

    You need to do it something like this, Add header in your ajax

        $.ajax({
            headers: {
               'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url: 'upload.php',
            data: form_data,                         
            type: 'post',
            success: function(response){
                alert(response); 
            }
         });
    
    

    And now you should have below given meta tag in head of your HTML

    <meta name="csrf-token" content="{ csrf_token() }">
    

    This will fix the csrf error.

    or

    try this

            $.ajax({
                url: 'upload.php',
                data: {
                     "_token": "{ csrf_token() }",
                     "id": id
                },                         
                type: 'post',
                success: function(response){
                     alert(response); 
                 }
            });