在Internet Explorer中FormData不起作用?

4
    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);
}

这个函数好像没起作用。我正在调用的函数如下:
onClick="uploadPhoto(document.getElementById('ID-HERE').files[0]);"

当我从files[]中删除0后,它至少可以运行postStatus();,但无法上传照片。我该如何解决这个问题?

你在说哪个版本的IE? - Pointy
1
caniuse.com file api - epascarello
我认为这就是问题,@Jake。文件 API 直到 IE10 才被支持。 - Pointy
1个回答

5

在IE浏览器中,只有IE10及以上版本的XHR支持FormData。您可以安装Windows 8客户预览版来尝试一下。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接