2015-02-12 80 views
1

我有一个问题,试图删除我调用数据库后通过dropzone.js文件。填写dropzone.js与图像从数据库问题删除图像

当我导航到页面并上传新图像,然后在不刷新页面的情况下将其删除后,它将按预期工作。

下面是我目前的上传方法

myDropzone.on("success", function (file, response) { 
        console.log(response); 
        file.serverId = response; 
       }); 

这是什么做的console.log(响应)后的反应中;

Object { UniqueId="evgopvdjfs1w9sos3jt5"} 

这是正确的。

现在,当我按下F5并刷新页面时,我用下面的代码片段填充了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'], 

说它的underfined,我个人无法看到,因为这两个console.logs显示UniqueId,这让我想知道当我预先填充dropzone与im年龄?你可以看到我有一个console.log(文件);在删除功能当中,当点击显示以下内容时

Object { name="evgopvdjfs1w9sos3jt5", UniqueId="evgopvdjfs1w9sos3jt5"} 

任何人都可以看到最新的错误吗?

回答