laravel dropzone 合并表单错误 405(方法不允许)
laravel dropzone combine form error 405 (Method Not Allowed)
美好的一天,我已经成功地将 dropzone 与普通形式结合起来并且它可以工作但是每次我尝试使用方法 PUT 或 PATCH 更新 post(用户内容)时,我收到错误 405(方法不允许) .
post 更新在没有 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>
尝试将方法更改为 POST 并将 _method 和 _token 输入附加到发送的 formData。每次我使用不是 GET、HEAD 或 POST 的 HTTP 动词时,我都会将这些字段和 POST 包含到 URL.
美好的一天,我已经成功地将 dropzone 与普通形式结合起来并且它可以工作但是每次我尝试使用方法 PUT 或 PATCH 更新 post(用户内容)时,我收到错误 405(方法不允许) . post 更新在没有 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>
尝试将方法更改为 POST 并将 _method 和 _token 输入附加到发送的 formData。每次我使用不是 GET、HEAD 或 POST 的 HTTP 动词时,我都会将这些字段和 POST 包含到 URL.