最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - FormData not working in Internet Explorer? - Stack Overflow

programmeradmin3浏览0评论
    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();, but it won't upload the photo. How do I go about fixing this?

    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();, but it won't upload the photo. How do I go about fixing this?

Share Improve this question asked Mar 5, 2012 at 20:36 JakeJake 1,5014 gold badges19 silver badges41 bronze badges 3
  • What version of IE are you talking about? – Pointy Commented Mar 5, 2012 at 20:41
  • 1 caniuse. file api – epascarello Commented Mar 5, 2012 at 20:53
  • Well I think that's the problem, @Jake. The file API isn't supported until IE10. – Pointy Commented Mar 5, 2012 at 20:58
Add a ment  | 

1 Answer 1

Reset to default 5

The XHR in IE doesn't support FormData until IE10. You may install Windows 8 Customer Preview to have a try.

发布评论

评论列表(0)

  1. 暂无评论