FormData 在 Internet Explorer 中不起作用

FormData not working in Internet Explorer?

本文关键字:不起作用 Explorer Internet FormData      更新时间:2023-09-26
    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 中的 XHR 在 IE10 之前不支持 FormData。您可以安装 Windows 8 客户预览版进行尝试。