2011-09-14 2 views
2

XMLHTTPRequest를 사용하여 파일 업로드 진행 방법을 궁금합니다. Firefox에서는 onprogress 메소드가 전혀 실행되지 않으며 크롬에서 파일 업로드가 완료된 후에 만 ​​실행됩니다.파일 업로드시 진행 상황 XMLHttpRequest를 통해

function fileUpload(file) 
{ 
    var formData = new FormData(); 
    formData.append('file', file); 

    var xhr = new XMLHttpRequest(); 
    xhr.onprogress = function(e) 
    { 
     alert('progress'); 
    }; 

    xhr.open('POST', 'post.php', true); 

    xhr.send(formData); // multipart/form-data 
} 

답변

7

시도 xhr.upload.onprogress. XMLHttpRequest2 spec XMLHttpRequest에는 업로드 속성이 있습니다.

진행률 이벤트에 등록 할 수있는 기능. 다운로드 (XMLHttpRequest 객체 자체에 수신기를 넣음)와 업로드 ( 속성에 의해 반환 된 XMLHttpRequestUpload 객체에 수신기를 넣음). http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#differences