如果我使用 multipart/form-data 获取图像数据,为什么图像上传功能在 Internet Explorer9 中不起作用。如何在 Internet Explorer 中上传图片。
这是我用来上传图片的代码。
var formData = new FormData($('form')[1]);
var onclick_attr=$('#Upload').attr('onclick');
$.ajax({
url: '${pageContext.servletContext.contextPath}/UploadImage',
data: formData,
type: 'POST',
cache: false,
contentType: false,
processData: false,
beforeSend: function(xhr) {
$('#process-img-div').hide();
$('#uploading-img').show();
$('#Upload').attr('onclick','').css('opacity','0.5');
$('#loader-imgforlogo').show();
},
success: function(xhr) {
var str = xhr.split('&');
for(var i=0; i<str.length; i++) {
var keys = str[i].split(':');
if(keys[0]=='Name')
fileName = keys[1];
else if(keys[0]=='Width')
imgWidth = keys[1];
else if(keys[0]=='Height')
imgHeight = keys[1];
else if(keys[0]=='Path')
filePath = keys[1];
}
$('#preview').attr({
'src':'${pageContext.servletContext.contextPath}/uploads/'+fileName
});
$('#process-img-div').show();
$('#uploading-img').hide();
},
complete:function(jqXHR, textStatus){
$('#Upload').attr('onclick',onclick_attr).css('opacity','1');
$('#loader-imgforlogo').hide();
$.fancybox.close();
},
error: function(xhr) {
}
});
}