How to include the CSRF token in the headers in Dropzone upload request?

前端 未结 9 1836
难免孤独
难免孤独 2020-12-13 18:19

I am working on a single page application and I am using Laravel 5 for the web service.

All forms are submitted asynchronously and I use a beforeSend on them to atta

9条回答
  •  被撕碎了的回忆
    2020-12-13 18:43

    For anyone using default Laravel setup:

    window.Laravel = {!! json_encode([
        'csrfToken' => csrf_token(),
    ]) !!};
    
    Dropzone.options.attachments = {
        url: 'upload',
        headers: {
            'X-CSRF-TOKEN': Laravel.csrfToken
        }
    }
    

提交回复
热议问题