gpt4 book ai didi

jquery - 除非刷新页面,否则 Dropzone 不会加载

转载 作者:行者123 更新时间:2023-12-01 04:01:58 24 4
gpt4 key购买 nike

我在 Rails 应用程序中使用 dropzone.js。拖放区是具有其他输入元素的表单的一部分。在页面加载时,包含表单的 div 被隐藏。单击按钮后,该 div 就会向下滑动。然而,现阶段 Dropzone 尚未初始化。但如果我刷新页面并再次单击相同的按钮,它就完全可以正常工作。

这是我的 dropzone 函数(在 document.ready 内)

function dropzoneControl() {
Dropzone.options.myDropzone = {
url: '/the_url',
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 5,
maxFiles: 5,
maxFilesize: 3,
acceptedFiles: 'image/*',
addRemoveLinks: true,
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
},
init: function() {
dzClosure = this;
document.getElementById("submit-button").addEventListener("click", function(e) {
e.preventDefault();
e.stopPropagation();
dzClosure.processQueue();
});

//send all the form data along with the files:
this.on("sendingmultiple", function(data, xhr, formData) {
formData.append("name", $("#name").val()); * * other data * *

});

//on successful upload
this.on("successmultiple", function(file, responseText) {
$('#name').val(""); * * clear the rest of the form * *
});

this.on("queuecomplete", function(file) {
this.removeAllFiles();
});
}
}
}

最佳答案

问题出在涡轮链接上。当我从另一个页面进入该页面时,拖放区不起作用。但是直接刷新就可以了。将 data-no-turbolink 添加到包含页面链接的 div,现在效果很好。

关于jquery - 除非刷新页面,否则 Dropzone 不会加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39914123/

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