[英]BlueImp file upload plugin not working
I have a page that has the following input elemet: 我有一个页面,其中包含以下输入要素:
<input class="uploadDocument" type="file" name="FileData" id="my-upl" />
And then the following javascript for starting the upload: 然后使用以下JavaScript开始上传:
$("#my-upl").fileupload({ url: uploadUrl, dataType: 'string', done: successFunction, uploadProgress: function(e, data) { var pct = parseInt(data.loaded / data.total * 100, 10); updateProgressBar(progressDiv, progressBar, progressLabel, Math.round(pct)); }, fail: function(e, data) { var errorHtml = uploadFailedHtml + "<p>" + data.textStatus + "</p>"; showModal(uploadFailedTitle, errorHtml); } });
It seems that the file upload does not trigger. 文件上传似乎没有触发。 I've even tried specifying a "start" and an "always" callback to see if anything gets triggered but to no avail.
我什至尝试指定“开始”和“始终”回调,以查看是否触发了任何操作但无济于事。
EDIT: I've added an "add" callback and this does get triggered when the file is selected but the upload does not start. 编辑:我添加了一个“添加”回调,当选择了文件但上传没有开始时,确实会触发该回调。
The answer was found by looking at what code is run when using a button to start the upload 通过查看使用按钮开始上传时运行的代码找到了答案
In my add callback, I simply had to do data.submit()
: 在我的添加回调中,我只需要做
data.submit()
:
$("#my-upl").fileupload({ url: uploadUrl, dataType: 'string', done: successFunction, uploadProgress: function(e, data) { var pct = parseInt(data.loaded / data.total * 100, 10); updateProgressBar(progressDiv, progressBar, progressLabel, Math.round(pct)); }, fail: function(e, data) { var errorHtml = uploadFailedHtml + "<p>" + data.textStatus + "</p>"; showModal(uploadFailedTitle, errorHtml); }, add: function(e, data) { data.submit(); return true; } });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.