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.
You can try putting the token in the sent data
data: {
"_token": "{{ csrf_token() }}",
"id": uploadedImages[file.name]
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With