【发布时间】:2013-12-14 16:31:04
【问题描述】:
我有一个元素,当我单击它会打开输入对话框并上传所选照片。服务器使用 4 个项目作为 JSON OBJECT 响应请求:NAME,TYPE,HEIGHT,WIDTH.
我想要的是在成功的 ajax 上传过程之后,用新上传的照片重新加载/刷新元素背景。到目前为止,我已经穿了这些:
JS:
$(document).ready(function() {
$("input[name!='photo_1']").parents('.fileinput-wrapper').find(".label").remove();
$("input[type=file]").on('change',function(){
$(this).parents('label').find('.fileinput-preview').css('background','url(http://localhost/project/assets/images/ajax-loader.GIF) no-repeat center center');
var selectedElement = this;
var name = $(this).attr('name').toString();
$('#upload').ajaxSubmit({
dataType:'json',
data: {name:name},
beforeSubmit:function(){
$(selectedElement).parents('label').find('input[type=file]').attr('disabled','disabled');
},
success: function(data) {
$(selectedElement).parents('label').find('.fileinput-preview').css('background',"url('http://localhost/project/assets/images/loading.png') no-repeat center center");
$.each(data, function(index, item) {
$(selectedElement).parents('label').find('.fileinput-preview').css('background',"url('http://localhost/project/uploads/"+ item.NAME +") no-repeat center center");//**replacing part**
});
$(selectedElement).parents('label').find('input[type=file]').removeAttr('disabled');
return false;
},
error : function(xhr) {
alert(xhr.responseText);
return false;
}
});
});
});
问题是它替换了背景权利,但图像未加载并显示为空白。我该怎么办?
【问题讨论】:
-
您好像不是在上传照片...您发送的只是
name?
标签: javascript jquery css ajax json