【发布时间】:2015-04-12 20:37:37
【问题描述】:
我在调用数据库后尝试删除通过 dropzone.js 的文件时遇到问题。
当我导航到该页面并上传新图像,然后在不刷新页面的情况下将其删除时,一切都按预期工作。
以下是我目前的上传方式
myDropzone.on("success", function (file, response) {
console.log(response);
file.serverId = response;
});
这是执行 console.log(response); 后响应中的内容;
Object { UniqueId="evgopvdjfs1w9sos3jt5"}
哪个是正确的。
现在,当我按 F5 并刷新页面时,我会使用以下 sn-p 填充 dropzone,这会返回我刚刚上传的图像。
$.getJSON("/Person/GetPreviews/").done(function (data) {
if (data.Data != '') {
$.each(data.Data, function (index, item) {
var UniqueId = item.ImageName;
var mockFile = {
name: item.ImageName,
serverId: UniqueId // This is what I need to delete the image
};
console.log(mockFile);
// Call the default addedfile event handler
myDropzone.emit("addedfile", mockFile);
// And optionally show the thumbnail of the file:
myDropzone.emit("thumbnail", mockFile, item.ImageUrl);
myDropzone.files.push(mockFile);
});
}
});
现在当我做 console.log(mockFile);如下所示,再次正确。
Object { name="evgopvdjfs1w9sos3jt5", UniqueId="evgopvdjfs1w9sos3jt5"}
现在说到删除文件,这是我当前的删除功能
removedfile: function (file) {
console.log(file);
$.ajax({
type: 'POST',
url: '@Url.Action("DeleteUploadedFile", "Person", new {userId= @Model.UserId})',
data: "id=" + file.serverId['UniqueId'],
dataType: 'html',
});
var ref;
return (ref = file.previewElement) != null ? ref.parentNode.removeChild(file.previewElement) : void 0;
},
现在,当我从数据库中按预填充图像上的删除文件时,它会在
上引发错误data: "id=" + file.serverId['UniqueId'],
说它不够精细,我个人看不出是怎么回事,因为两个 console.logs 都显示了 UniqueId,这让我想知道当我用图像预先填充 dropzone 时我是否遗漏了什么?
如您所见,我有一个 console.log(file);在删除功能中,点击时显示以下内容
Object { name="evgopvdjfs1w9sos3jt5", UniqueId="evgopvdjfs1w9sos3jt5"}
任何人都可以看到有什么问题吗?
【问题讨论】: