[英]FormData not working in Internet Explorer?
function uploadPhoto(file) {
if (!file || !file.type.match(/image.*/)){
if(!file){
postStatus();
} else {
return;
}
}
var fd = new FormData();
fd.append("image", file);
fd.append("privacy", document.getElementById('privacy-handler').value);
var xhr = GetXmlHttpRequest();
xhr.open("POST", "url here");
slideUp('photo-upload');
slideDown('photo-manager-txt');
document.getElementById("photo-manager-txt").innerHTML='<i>Please wait a moment while we process your photo.</i>';
xhr.onload = function() {
if(xhr.responseText == '0'){
document.getElementById('photo-manager-txt').innerHTML='<br />Photo upload failed';
slideDown('photo-upload');
return;
} else {
document.getElementById('photo-txt').value='grab?v=1&file='+xhr.responseText;
document.getElementById('photo-manager-txt').innerHTML='Photo uploaded and shared.';
postStatus();
}
}
xhr.send(fd);
}
This function seems not to be working. 这个功能似乎不起作用。 When I call the function I'm using: 当我调用我正在使用的函数时:
onClick="uploadPhoto(document.getElementById('ID-HERE').files[0]);"
When I remove the 0
from files[]
, it atleast runs postStatus();
当我从files[]
删除0
,它至少会运行postStatus();
, but it won't upload the photo. ,但它不会上传照片。 How do I go about fixing this? 我该如何解决这个问题?
The XHR in IE doesn't support FormData until IE10. IE中的XHR在IE10之前不支持FormData。 You may install Windows 8 Customer Preview to have a try. 您可以安装Windows 8 Customer Preview进行试用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.