2012-03-05 2 views
4
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); 
} 

이 함수는 작동하지 않는 것 같습니다. 내가 사용하고 함수를 호출 할 때 :FormData가 Internet Explorer에서 작동하지 않습니까?

onClick="uploadPhoto(document.getElementById('ID-HERE').files[0]);" 

나는 files[]에서 0은이어야가 postStatus(); 실행, 제거,하지만 사진을 업로드하지 않을 때. 이 문제를 해결하려면 어떻게해야합니까?

+0

무슨 IE 버전입니까? – Pointy

+0

Internet Explorer 9 – Jake

+1

[caniuse.com file api] (http://caniuse.com/#search=file%20api) – epascarello

답변

5

IE의 XHR은 IE10까지 FormData를 지원하지 않습니다. Windows 8 고객 미리보기를 설치하여 사용해 볼 수 있습니다.

+3

ie-10 이상에서 작동하는 이유는 무엇입니까? –

관련 문제