gpt4 book ai didi

jquery - Uncaught Error : Dropzone already attached

转载 作者:行者123 更新时间:2023-12-01 07:46:59 29 4
gpt4 key购买 nike

在asp.net中使用Dropzone插件在许多页面中进行上传时,我尝试将脚本放入用户控件中以便多次使用它,但我收到此错误:未捕获错误:Dropzone已附加。我做了很多搜索,发现一些解决方案并没有解决我的问题,例如添加 Dropzone.autoDiscover = false;或 Dropzone.options.myAwesomeDropzone = false;这是用户控件中包含的脚本:

<script type="text/javascript">

$(document).ready(function () {
var currentDropzoneContent = '#<%=DropContent.ClientID %>';
var currentDropzone = 'div#<%=dropzonefile2.ClientID %>';
var dzMessage = $(currentDropzone).children('.dz-message');
// Dropzone
$(currentDropzone).dropzone({
url: "/AdminAjax/FileManager/UploadFile",
clickable: false,
createImageThumbnails: true,
acceptedFiles: "image/*",
maxFiles: 1,
accept: function (file, done) {
done();
},
init: function () {
// drop
this.on("sending", function (file, xhr, data) {
var folderValue = $(currentDropzoneContent + " .typeDrop input:checked").val();
data.append("folderName", folderValue);
});

this.on("drop", function (e) {
dzMessage.text('Drag image here');
});
this.on("dragleave", function () {
dzMessage.text('Drag image here');
});
this.on("dragover", function () {
dzMessage.text('Drop image here');
});
// complete
this.on("complete", function (file) {

});
// canceled
this.on("canceled", function () {
});
// success
this.on("success", function (file, response) {

this.removeFile(file);
if ($.trim(response) != "") {
var imagePreview = '<%= ImagePreview %>';
var imageField = '<%= ImageField %>';
$('img#' + imagePreview).attr("src", response + '.ashx?bgcolor=E5E5E5&height=120&width=120');
$('#' + imageField).val(response);
}

});
this.on('addedfile', function (file) {

});

// error
this.on("error", function (file, response) {
this.removeFile(file);
});
}
});
});

这是 div 的代码 html,我在其中放置要上传的文件

<div class="mws-form">
<div class="mws-form-block">
<div class="mws-form-row">
<div class="mws-form-item">
<div id="DropContent" runat="server" class="mws-ui-button- radio">
<asp:RadioButton ID="Categories" CssClass="typeDrop" GroupName="typeDrop" runat="server"
Text="Categories" />
<asp:RadioButton ID="Products" CssClass="typeDrop" GroupName="typeDrop" runat="server"
Text="Products" />
<asp:RadioButton ID="Banners" CssClass="typeDrop" GroupName="typeDrop" runat="server"
Text="Banners" />
<asp:RadioButton ID="Manufacturers" CssClass="typeDrop" GroupName="typeDrop" runat="server"
Text="Manufacturers" />
</div>
</div>
</div>
</div>
</div>
<div ID="dropzonefile2" class="dropzonefile1 dropzone1 needsclick1 dz- clickable1 fade well" runat="server">
<div class="dz-message needsclick custText" >
Drag image here</div>
</div>

谢谢!

最佳答案

您必须将 autoDiscover 选项放在 $(document).ready 之前,例如:

//Dropzone Configuration
Dropzone.autoDiscover = false;

$(document).ready(function(){

// Pre init code
var currentDropzoneContent = '#<%=DropContent.ClientID %>';
var currentDropzone = 'div#<%=dropzonefile2.ClientID %>';
var dzMessage = $(currentDropzone).children('.dz-message');

// Dropzone manual init
$(currentDropzone).dropzone({
url: "/AdminAjax/FileManager/UploadFile",
clickable: false,
...
});
});`

关于jquery - Uncaught Error : Dropzone already attached,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35957329/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com