FormData not working in Internet Explorer?

半腔热情 提交于 2019-12-19 21:24:23

问题


    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?


回答1:


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



来源:https://stackoverflow.com/questions/9573607/formdata-not-working-in-internet-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!