Jquery Dropzonejs,从服务器中删除,而不是从页面中删除
我正在使用dropzonejs,它在服务器中工作,它保存,当我单击删除按钮时,它将从服务器中删除。但唯一的问题是,当我点击删除按钮时,图片仍保留在页面上。我认为这是因为jquery代码。但我无法解决它 在这里Jquery Dropzonejs,从服务器中删除,而不是从页面中删除,jquery,ruby-on-rails,ajax,drag,Jquery,Ruby On Rails,Ajax,Drag,我正在使用dropzonejs,它在服务器中工作,它保存,当我单击删除按钮时,它将从服务器中删除。但唯一的问题是,当我点击删除按钮时,图片仍保留在页面上。我认为这是因为jquery代码。但我无法解决它 在这里 <div class="container"> <%= form_for [@boat, @picture], html: { multipart: true, url: wizard_path, class: "dropzone", id: "picture-drop
<div class="container">
<%= form_for [@boat, @picture], html: { multipart: true, url: wizard_path, class: "dropzone", id: "picture-dropzone"} do |f| %>
<p>
<div class="fallback">
<%= f.file_field :image %>
</div>
</p>
<% end %>
<p><%= link_to "Back to My Profile", current_user %></p>
<div class="index">
<%= render "index" %>
</div>
<script type="text/javascript">
$(document).ready(function(){
// disable auto discover
Dropzone.autoDiscover = false;
// grap our upload form by its id
$("#picture-dropzone").dropzone({
// restrict image size to a maximum 5MB
maxFilesize: 5,
// changed the passed param to one accepted by
// our rails app
paramName: "picture[image]",
acceptedFiles: "image/*",
// show remove links on each image upload
addRemoveLinks: false,
// if the upload was successful
success: function(file, response){
// find the remove button link of the uploaded file and give it an id
// based of the fileID response from the server
$(file.previewTemplate).find('.dz-remove').attr('id', response.fileID);
$(file.previewTemplate).find('.dz-remove').attr('boat_id', response.boatID);
// add the dz-success class (the green tick sign)
$(file.previewElement).addClass("dz-success");
},
//when the remove button is clicked
removedfile: function(file){
// grap the id of the uploaded file we set earlier
var id = $(file.previewTemplate).find('.dz-remove').attr('id');
var boat_id = $(file.previewTemplate).find('.dz-remove').attr('boat_id');
// make a DELETE ajax request to delete the file
$.ajax({
type: 'DELETE',
url: '/boats/' + boat_id + '/pictures/' + id,
success: function(file){
removeFile(file); // THIS DOES NOT WORK
//SOMETHING HERE
}
});
}
});
});
</script>
$(文档).ready(函数(){
//禁用自动发现
Dropzone.autoDiscover=false;
//根据上传表单的id对其进行绘图
$(“#图片dropzone”).dropzone({
//将图像大小限制为最大5MB
最大文件大小:5,
//将传递的参数更改为接受的参数
//我们的rails应用程序
paramName:“图片[图像]”,
acceptedFiles:“image/*”,
//显示每个图像上载上的删除链接
addRemoveLinks:false,
//如果上传成功
成功:函数(文件、响应){
//找到上传文件的“删除”按钮链接,并为其提供一个id
//基于来自服务器的fileID响应
$(file.previewTemplate).find('.dz remove').attr('id',response.fileID);
$(file.previewTemplate).find('.dz remove').attr('boat_id',response.boatID);
//添加dz成功类(绿色勾号)
$(file.previewElement).addClass(“dz成功”);
},
//单击“删除”按钮时
removedfile:函数(文件){
//grap我们之前设置的上传文件的id
var id=$(file.previewTemplate).find('.dz remove').attr('id');
var boat_id=$(file.previewTemplate).find('.dz remove').attr('boat_id');
//发出删除ajax请求以删除该文件
$.ajax({
键入:“删除”,
网址:'/boats/'+boat_id+'/pictures/'+id,
成功:函数(文件){
removeFile(file);//这不起作用
//这里有东西
}
});
}
});
});