上传图片后如何重新加载页面 [英] how to reload page after uploading images
本文介绍了上传图片后如何重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将宝石'jquery-fileupload-rails'和'carrierwave_backgrounder'宝石与sidekiq一起使用.下载完成后如何添加重新加载页面?
I use gem 'jquery-fileupload-rails' and 'carrierwave_backgrounder' gem with sidekiq. How to add reload the page after download is complete?
问题在于,下载位于后台中,并且该页面会立即重新加载,而不是在加载图像时重新加载
The problem is that the download is in the background and the page is reloaded immediately, not when the images loaded
fileupload.js
fileupload.js
$(function () {
$('#new_photo').fileupload({
acceptFileTypes: '/(\.|\/)(gif|jpe?g|png)$/i',
dataType: 'html',
add: function (e, data) {
data.context = $('#loading').css({display:"block"}).appendTo('#photos');
data.submit();
},
done: function (e, data) {
data.context.text('Upload finished.');
location.reload();
}
});
});
image_upload.html.erb
image_upload.html.erb
<div class="upload" id="new_photo">
<%= form_for([@project, current_user.photos.new]) do |f| %>
<%= file_field_tag :image, multiple: true, name: "photo[image]" %>
<%= link_to 'Save', @project, :class => 'btn btn-success' %>
<% end %>
<div id="loading">
<h4>Loading</h4>
</div>
</div>
<div class="image-upload">
<% @project.photos.each do |photo| %>
<%= image_tag photo.image_url.to_s %>
<p><%= link_to "Delete", project_photo_path(@project, photo), :method => :delete, :class => 'btn' %></p>
<% end %>
</div>
推荐答案
>有关回调的jquery fileuploader文档,您可以绑定success
事件,该事件将在上传完成后触发.
from the jquery fileuploader documentation on callbacks, you can bind a success
event that will be triggered after upload finishes.
jqXHR = data.submit()
.success(function() { window.location.reload() })
这篇关于上传图片后如何重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文