【问题标题】:laravel dropzone combine form error 405 (Method Not Allowed)laravel dropzone组合表单错误405(不允许方法)
【发布时间】:2017-11-15 01:16:55
【问题描述】:

美好的一天,我已经成功地将 dropzone 与普通表单结合起来,并且它可以工作,但是每次我尝试使用方法 PUT 或 PATCH 更新帖子(用户内容)时,我都会收到错误 405(不允许使用方法)。 没有 dropzone 的更新后工作,但是当图像添加到 dropzone 时我得到错误 405(不允许的方法)

            <form id="addproduct" enctype="multipart/form-data" method="POST" action="{{ route('admin.posts.update', $post->id) }}">
                {{ csrf_field() }}
                {{method_field('PATCH')}}

                <input class="form-control" name="title">
                <div id="myAwesomeDropzone" class="dropzone"></div>
                <button type="button" id="submit_form" class="btn btn-primary">Send</button>
            </form>


            <script>

            Dropzone.options.myAwesomeDropzone = {
                url: '/admin/posts/{!! json_encode($post->id) !!}',
                method: 'PUT',
                autoProcessQueue: false,
                uploadMultiple: true,
                parallelUploads: 3,
                maxFiles: 3,
                addRemoveLinks: true,
                thumbnailMethod: 'crop',
                resizeWidth: 500,
                resizeHeight: 500,
                resizeQuality: 0.3,
                acceptedFiles: ".jpg, .jpeg, .png",
                dictDefaultMessage: "Drop your files here!",


                init: function () {
                    var myDropzone = this;
                    $('#submit_form').on("click", function (e) {
                        e.preventDefault();
                        e.stopPropagation();
                        myDropzone.processQueue();      
                    });



                    this.on("sending", function(file, xhr, formData){
                        $('#addproduct').each(function() {
                            title = $(this).find('input[name="title"]').val();
                            formData.append('title', title);
                        });
                    });
                    this.on("success", function(file, response) {

                    });
                    this.on("completemultiple", function(files) {
                        // Here goes what you want to do when the upload is done
                        // Redirect, reload , load content ......

                    });
                },

            };

            </script>

【问题讨论】:

    标签: jquery laravel-5 laravel-5.3 dropzone.js


    【解决方案1】:

    尝试将方法更改为 POST 并将 _method 和 _token 输入附加到发送的 formData。每次我使用不是 GET、HEAD 或 POST 的 HTTP 动词时,我都会包含这些字段并 POST 到 URL。

    【讨论】:

      猜你喜欢
      • 2018-07-06
      • 2015-10-15
      • 2017-09-03
      • 2019-07-29
      • 2018-01-25
      • 1970-01-01
      • 2021-12-20
      • 2017-11-13
      • 2018-03-07
      相关资源
      最近更新 更多