kra*_*r65 8 html javascript file-upload dropzone.js
我刚刚实现了Dropzone.js,以便在我的网站上轻松上传文件.文件上传很好,上传完成后我给文件一个id并将这个id返回给浏览器.
这工作正常,除了我不知道如何捕获从服务器返回的id.在这个SO答案中,我发现了一些应该这样做的代码,但它对我不起作用.我现在的代码粘贴在下面.
有谁知道我如何获得服务器返回的值?欢迎所有提示!
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/static/js/external/dropzone.min.js"></script>
<link href="/static/css/external/dropzone.css" rel="stylesheet">
<script type="text/javascript">
$(function() {
Dropzone.options.uiDZResume = {
success: function(file, response){
console.log('WE NEVER REACH THIS POINT.');
alert(response);
}
};
});
</script>
</head>
<body>
<form action="/doc"
class="dropzone"
id="my-awesome-dropzone"></form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
tom*_*aoq 19
查看dropzone.js的源代码,似乎有很多事件可以听.
events: [
"drop"
"dragstart"
"dragend"
"dragenter"
"dragover"
"dragleave"
"addedfile"
"removedfile"
"thumbnail"
"error"
"errormultiple"
"processing"
"processingmultiple"
"uploadprogress"
"totaluploadprogress"
"sending"
"sendingmultiple"
"success"
"successmultiple"
"canceled"
"canceledmultiple"
"complete"
"completemultiple"
"reset"
"maxfilesexceeded"
"maxfilesreached"
]
Run Code Online (Sandbox Code Playgroud)
这里的"成功"事件似乎是恰当的.
一个很好的起点是将事件监听器绑定到您的dropzone,并查看您在此类事件中获得的数据.
$('#my-awesome-dropzone').on('success', function() {
var args = Array.prototype.slice.call(arguments);
// Look at the output in you browser console, if there is something interesting
console.log(args);
});
Run Code Online (Sandbox Code Playgroud)
小智 8
$("#dropzoneForm").dropzone({
maxFiles: 2000,
url: "../Uploader/HttpUploadHandler.ashx?param=" + result.prjID,
success: function(file, response){
//alert("Test1");
}
});
Run Code Online (Sandbox Code Playgroud)
这有帮助吗?
Dropzone.options.myDropzone = {
init: function() {
thisDropzone = this;
this.on("success", function(file, responseText) {
var responseText = file.id // or however you would point to your assigned file ID here;
console.log(responseText); // console should show the ID you pointed to
// do stuff with file.id ...
});
}
};
Run Code Online (Sandbox Code Playgroud)
例如,我已将我的设置附加到图像名称的服务器路径,并将其作为值传递到提交中的表单字段.只要您定义responseText以指向文件ID,您就应该得到一个返回.
此链接也可能有用:https://github.com/enyo/dropzone/issues/244