2012-03-05 129 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,它ATLEAST運行postStatus();,但它不會上傳照片。我該如何解決這個問題?

+0

你在說什麼版本的IE? – Pointy 2012-03-05 20:41:00

+0

Internet Explorer 9 – Jake 2012-03-05 20:43:30

+1

[caniuse.com file api](http://caniuse.com/#search=file%20api) – epascarello 2012-03-05 20:53:18

回答

5

IE中的XHR在IE10之前不支持FormData。您可以安裝Windows 8 Customer Preview來嘗試。

+3

爲什麼我要它,如果它在ie-10或以上的作品? – 2013-02-07 08:26:40

相關問題