【发布时间】:2014-04-04 12:09:38
【问题描述】:
我有一个文件上传按钮,它通过 ajax 上传文件,我通过每 3 秒发送一次 ajax 请求来显示上传的图片,问题是,我想在用户点击上传按钮时显示加载图像和成功隐藏它,但图像未显示。如上所述,我有另一个 ajax 调用来获取上传的图片,我认为它隐藏了图片。所以我想要的只是,当用户单击按钮显示加载图像时,当第二个 ajax 调用将上传的图像显示给用户时,隐藏图像。有人可以给我提示吗?
$("#loading_image").html('<div class="loadm"><img src="../image/ajax-loader.gif"/>//I have tried putting the loading image on the also.
$(document).ready(function()
{
profileRefresh();
var uploaded_files_location = "../img/";
new AjaxUpload($('#upload_button '),
{
hoverClass: 'btn - primary',
action: 'picture.php ? target = profile ',
name: 'file_to_upload ',
onSubmit: function(file, file_extensions){
$('#errormsg ').html('');
if (!(file_extensions && /^(jpg|png|jpeg|gif|JPG)$/.test(file_extensions)))
{
$('#error ').html(' < div class = "error" align = "left" > Sorry, you can only upload the following file formats : JPG, JPEG, PNG and GIF... < /div>');
return false;
}
else
{
$("#loading_image").html('<div class="loadm"><img src="../image / ajax - loader.gif "/></div>');//this is the loading image that is not showing.
return true;
}
},
onComplete: function(file, response){}
});
});
var profileRefresh = function() {
$.ajax({
type: "GET ",
url: "picture ? target = refresh ",
success: function(response){
$("#pro").html(response);
setTimeout(profileRefresh, 3000);
$("#loading_image ").fadeOut('fast');// hide the loading image
}
});
};
【问题讨论】:
-
要设置还是获取图片?
-
@Soombinakundi 直到通过第二次 ajax 调用将上传的图像显示给用户,然后继续显示加载图像。