Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marinhogomes's avatar

Ajax error CSRFtoken error

I'm adding an imageuploader to my form.

I'm using the dropzoneJS to send the image via Ajax.

But nothing is really happening, the ajax post is not working and is returning to me:

TokenMismatchException

I'm guessing the Ajax is not sending the CSRF, how can I fix this??

The class sends it automatically through their JS function.

I have to add CSRF token somewhere... and some how??

0 likes
2 replies
RachidLaasri's avatar
Level 41

In your HTML head

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

And your jQuery :

$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
});
1 like
marinhogomes's avatar

Now I'm having problems with dropzone.

It doesn't seem like it's grabbing the files input and the FORM has image = true

The whole day struggling with this script so far.

Found out is something with the Dropzone script that doesn't pass the file as a file... but as an array if you change one of it's settings.

Please or to participate in this conversation.