【发布时间】:2020-01-28 14:48:47
【问题描述】:
我尝试了几种不同的方法,但我无法让它发挥作用。
我正在尝试在Change Dropzone url dynamically这里关注这个答案
我有一个包含各种字段的 for 和两个 dropzone 实例。一个工作正常,但是这个需要根据每个文件动态生成的链接将文件上传到保管箱。
我正在尝试更新基于来自服务器的 ajax 响应处理的每个文件的 dropzone url 参数。
我知道 ajax 可以正常工作并获取我需要的 URL。
jQuery(document).ready(function(){
Dropzone.autoDiscover = false
jQuery("#files-uploader").dropzone({
url: 'url.com',
init: function(){
var dropzoneobject=this;
this.on("processing", function (file) {
jQuery.ajax({
url:vendor_ajax_object.ajax_url,
type:'POST',
data:'action=knpGetUploadLink&filename='+file['name'],
success: function(data){
//data = a URL returned from the server
dropzoneobject.options.url = data;
},
error: function(){
}
});
});
},
headers: {
'content-type': 'application/octet-stream'
},
success: function (file, response) {
console.log(response);
file.previewElement.classList.add("dz-success");
},
error: function (file, response) {
console.log(response);
file.previewElement.classList.add("dz-error");
},
// update the following section is for removing image from library
addRemoveLinks: true,
removedfile: function(file) {}
});
});
将数据变量记录到控制台表明服务器已返回正确的 URL。 在 ajax 成功参数中记录 dropzoneobject.options.url 显示设置的正确 URL。 Dropzone 说它已成功上传,但开发工具中的网络选项卡显示发布到的 URL 是 url.com。
我认为我的时间在某个地方搞砸了。
任何建议都会很棒。
TIA。
【问题讨论】: