Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Token Mismatch exception when ajax Delete request sent in Laravel 5 when I change project folder

I used Dropzone.js to upload images. When I want to Delete image, I sent Ajax Delete request to Image Controller.

        myDropzone.on("removedfile", function(file) {      
            console.log(file.name);
            console.log(uploadedImages[file.name]);
            var csrf = $('input[name=_token]').val();
            // var csrf = $('meta[name="_token"]').attr('content');
            console.log(csrf);
           var request = $.ajax({
                url: "/cms/image/"+uploadedImages[file.name],
                headers: {
                    'X-CSRF-Token': csrf ,
                    "Accept": "application/json"
                },
                type: "DELETE",
                data: {  "id": uploadedImages[file.name] },
                error: function(jqXHR, textStatus, errorThrown) {
                    // alert('HTTP Error: '+errorThrown+' | Error Message: '+textStatus);
                    console.log(errorThrown);
                },

That method successfully sent to Controller with delete request in my old project.

But I merge in other project, I got the error.

TokenMismatchException in VerifyCsrfToken.php

I don't understand why that exception occur. Please explain me about that. Thanks and respect to all geeks.

like image 900
Thatoe Aung Avatar asked Jan 09 '23 17:01

Thatoe Aung


1 Answers

You can try putting the token in the sent data

data: {  
   "_token": "{{ csrf_token() }}",
   "id": uploadedImages[file.name] 
},
like image 77
Ilker Mutlu Avatar answered Jan 21 '23 22:01

Ilker Mutlu