FormData не работает в Internet Explorer? - PullRequest
4 голосов
/ 06 марта 2012
    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]);"

Когда я удаляю 0 из files[], она как минимум запускает postStatus();, но не загружает фотографию.Как мне исправить это?

1 Ответ

5 голосов
/ 06 марта 2012

XHR в IE не поддерживает FormData до IE10. Вы можете установить Windows 8 Customer Preview, чтобы попробовать.

...