【问题标题】:FormData not working in Internet Explorer?FormData 在 Internet Explorer 中不起作用?
【发布时间】:2012-03-23 08:03:24
【问题描述】:
    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?
  • 嗯,我认为这就是问题所在,@Jake。 IE10 之前不支持文件 API。

标签: javascript html ajax xmlhttprequest form-data


【解决方案1】:

IE 中的 XHR 直到 IE10 才支持 FormData。您可以安装 Windows 8 Customer Preview 来试一试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    • 2015-03-16
    • 2012-05-06
    • 2011-06-02
    • 2015-12-17
    • 2013-04-30
    • 2013-09-25
    相关资源
    最近更新 更多