gpt4 book ai didi

javascript - Dropzone.js 事件未触发

转载 作者:行者123 更新时间:2023-11-28 04:29:01 26 4
gpt4 key购买 nike

我在 Dom 中有 dropzone 表单和一些事件处理程序。但是,没有任何事件被触发。文件被发送到服务器就好了。我只是想从服务器获取响应消息,以便我可以将图像的链接添加到数据库

HTML:

<div>
<form action="/file/upload" class="dropzone" id="dropzoneForm" method="post"></form>
</div>

脚本:

$(function () {

Dropzone.autoDiscover = true;
Dropzone.options.dropzoneForm = {
init: function () {
this.on("success", function(response) {
alert('Success event fired! Check console');
console.log(response);
});
},

paramName: "file"

};

});

最佳答案

一段时间后,我想通了这个问题。由于某些原因,Dropzone.options 没有触发,因为它在 $(function{}) 内部。所以这是一个很有魅力的版本

<!DOCTYPE html>
<html lang="en"
<head>
<meta charset="UTF-8">
<title>Products</title
<!-- Bootstrap core CSS -->
<link href="assets/bootstrap/css/bootstrap.css" rel="stylesheet">

<!-- Dropzone css-->
<link rel="stylesheet" href="assets/css/plugins/dropzone/dropzone.css">
<link rel="stylesheet" href="assets/css/plugins/dropzone/basic.css">
</head>
<body>
<div class="container" style="margin-top: 300px">
<div class="well">

<form action="/file/upload" class="dropzone" id="dropzoneForm">
<div class="fallback">
<input type="file" name="file" multiple="multiple">
</div>
</form>

</div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="assets/plugins/dropzone/dropzone.js"></script>
<script>
Dropzone.options.dropzoneForm = {
dictDefaultMessage: 'Drop file here or click to upload!!!!!!!!',
addRemoveLinks: true,
init: function () {
this.on("addedfile", function(file) { alert("Added file."); });
}
};

</script>
</body>
</html>

关于javascript - Dropzone.js 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43434283/

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